ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Opening a spreadsheet using VB (https://www.excelbanter.com/excel-programming/274831-opening-spreadsheet-using-vbulletin.html)

patrick molloy

Opening a spreadsheet using VB
 

Private Sub cmfRefresh_Click()

Dim xlAPP As Object
Dim xlWB As Object

Set xlAPP = CreateObject("Excel.Application")

Set xlWB = _
xlAPP.workbooks.open("H:\May_Timesheet.xls")

xlWB.activesheet.calculate

xlWB.Close True

Set xlWB = Nothing

xlAPP.quit

Set xlAPP = Nothing

End Sub

Instead of using the createobject method, you could set a
reference to the VB6 object library inj the VB IDE.
Then dim xlApp as Excel.Application and then SET xlAp =
New Excel.Application
dim xlWB as Excel.Workbook

the code above uses "late binding" ie you dim an object
but the code doesn't know what it is until the programme
creates the object.
Setting a reference allows "early binding" as I
described, which is, apart from being better and nmore
efficient in regards to compiling the code, enables the
programmer to use intellisense when writing the code.

HTH
Patrick Molloy
Microsoft Excel MVP

Option Explicit
' prog ref to Excel 10 Object Library
Private Sub cmfRefresh_Click()

Dim xlAPP As Excel.Application
Dim xlWB As Excel.Workbook

Set xlAPP = New Excel.Application

Set xlWB = xlAPP.workbooks.open
("H:\May_Timesheet.xls")

xlWB.ActiveSheet.calculate


xlWB.Close True

Set xlWB = Nothing

xlAPP.quit

Set xlAPP = Nothing


End Sub




-----Original Message-----
Hello,
I have a spreadsheet (XP) with links to query's in

Access
XP and SQL 2000 that needs to be opened and refreshed
(Refresh All button is the one that works when done
manually) on all tabs. Would anyone be able to provide
some sample code in VB 6 that would show how to open and
refresh a spreadsheet, then save and close? The first 2
are more important though.

thanks,
Zac
.



All times are GMT +1. The time now is 03:11 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com