S
shams100
I'm looking for an example VBA Code to export or transfer query data
from MS Access
to Excel.
I use this code:
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets("Sheet1")
xlSheet.Name = "sheetName"
With xlApp
With xlSheet.QueryTables.Add(Connection:=MyConnect, _
Destination:=Range("A1"))
.CommandText = "My SQl query"
.Name = "clearingHouse"
.FieldNames = True
.BackgroundQuery = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
End With
Evry time I run it I got this message error after it open Excel
application and create the sheet with the name:
Method Range of Object_ global faild
Does anyone know wehere i can find some example VBA code to accomplish
this.
Thanks,
from MS Access
to Excel.
I use this code:
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets("Sheet1")
xlSheet.Name = "sheetName"
With xlApp
With xlSheet.QueryTables.Add(Connection:=MyConnect, _
Destination:=Range("A1"))
.CommandText = "My SQl query"
.Name = "clearingHouse"
.FieldNames = True
.BackgroundQuery = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
End With
Evry time I run it I got this message error after it open Excel
application and create the sheet with the name:
Method Range of Object_ global faild
Does anyone know wehere i can find some example VBA code to accomplish
this.
Thanks,