S
Shu
Hello,
When I use Union function in MS Access. It only works once
for two-times running. For example: if it works this time,
next time a error message pops up saying "Method Union of
object '_global' failed", but if I run it again, it works.
such happens alternatively.
Any help is appreciated.
the following is my code.
Private Sub Command0_Click()
Dim xl As Excel.Application
Dim xlwb As Excel.Workbook
Dim xlst As Excel.Worksheet
Dim tempFile As String
Set xl = CreateObject("Excel.Application")
xl.Visible = True
tempFile = "G:\RSBL Template2.xls"
Set xlwb = xl.Workbooks.Open(tempFile)
Set xlst = xlwb.Worksheets("SUMMARY")
Dim R1 As Excel.Range
Dim R2 As Excel.Range
Dim R3 As Excel.Range
Dim R4 As Excel.Range
Set R1 = xlst.Columns(1)
Set R2 = xlst.Columns(2)
Set R3 = xlst.Columns(3)
Set R4 = xlst.Columns(4)
Dim rngFrom As Excel.Range
Dim rngTo As Excel.Range
Set rngFrom = Sheets("SUMMARY").Union(R1, R2, R3, R4)
Set rngTo = xlst.Columns(1)
rngFrom.Copy
rngTo.Insert
End Sub
Thanks very much!
Regards
Shu
When I use Union function in MS Access. It only works once
for two-times running. For example: if it works this time,
next time a error message pops up saying "Method Union of
object '_global' failed", but if I run it again, it works.
such happens alternatively.
Any help is appreciated.
the following is my code.
Private Sub Command0_Click()
Dim xl As Excel.Application
Dim xlwb As Excel.Workbook
Dim xlst As Excel.Worksheet
Dim tempFile As String
Set xl = CreateObject("Excel.Application")
xl.Visible = True
tempFile = "G:\RSBL Template2.xls"
Set xlwb = xl.Workbooks.Open(tempFile)
Set xlst = xlwb.Worksheets("SUMMARY")
Dim R1 As Excel.Range
Dim R2 As Excel.Range
Dim R3 As Excel.Range
Dim R4 As Excel.Range
Set R1 = xlst.Columns(1)
Set R2 = xlst.Columns(2)
Set R3 = xlst.Columns(3)
Set R4 = xlst.Columns(4)
Dim rngFrom As Excel.Range
Dim rngTo As Excel.Range
Set rngFrom = Sheets("SUMMARY").Union(R1, R2, R3, R4)
Set rngTo = xlst.Columns(1)
rngFrom.Copy
rngTo.Insert
End Sub
Thanks very much!
Regards
Shu