LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
Shu Shu is offline
external usenet poster
 
Posts: 5
Default Union only works for sometimes.

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
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
union range Curt Excel Discussion (Misc queries) 9 April 20th 07 02:32 PM
UNION of Arrays - is possible? Marina Limeira Excel Discussion (Misc queries) 1 January 22nd 06 12:38 PM
How do I convert works file to excel without works software? CatMB Excel Discussion (Misc queries) 1 June 21st 05 04:12 PM
Help w/ Union Queries Jenn Excel Discussion (Misc queries) 1 January 12th 05 01:07 AM
VBA union of two ranges s[_2_] Excel Programming 1 August 21st 03 02:18 AM


All times are GMT +1. The time now is 10:21 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"