Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

calling specific xcell file from vb

Options
  • 26-08-2004 7:50pm
    #1
    Registered Users Posts: 2,586 ✭✭✭


    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 Posts: 5,700 ✭✭✭jd


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


  • Registered Users Posts: 2,586 ✭✭✭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