Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

calling specific xcell file from vb

  • 26-08-2004 07:50PM
    #1
    Registered Users, Registered Users 2 Posts: 2,589 ✭✭✭


    Looking to call a specific file from VB and insert info into data.
    I can open excel in general and write to a work sheet no problems but I want to write the data into a certain file:
    Dim objExcel As excel.Application
    Dim objWorkbook As excel.Workbook
    Dim objWorksheet As excel.Worksheet
    
    'Start the excel COM and make it visible.
    Set objExcel = GetObject("", "excel.application")
        objExcel.Visible = True
        
    'Start a workbook.
    Set objWorkbook = objExcel.Workbooks.Add
    
    'Turn off the alerts, otherwise user will have to confirm my actions.
        objExcel.DisplayAlerts = False
    
    'Depending on the users excel's settings, there could be many worksheet when starting a workbook.
    'Ensure there is only one worksheet.
    Do While objWorkbook.Worksheets.Count > 1
        Set objWorksheet = objWorkbook.Worksheets.Item(objWorkbook.Worksheets.Count)
        objWorksheet.Delete
    Loop
    
    'Set objWorksheet to the remaining worksheet.
    Set objWorksheet = ActiveSheet
    
    any suggestions


Comments

  • Registered Users, Registered Users 2, Paid Member Posts: 5,819 ✭✭✭jd


    just to be clear-
    you want to opn an excel spreadsheet and edit it?


  • Registered Users, Registered Users 2 Posts: 2,589 ✭✭✭gerire


    What I wanted was to open a specific file, with a specific line design on it, and input info from a list box. I just figured out what to do here's the solving line:
    'Start a workbook.
    Set objWorkbook = objExcel.Workbooks.Open("E:\New Folder (2)\Real\sht1.xls")
    
    instead of .Add


Advertisement