A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » Charts and Charting
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Excel VBA method Cells of object _global failed



 
 
Thread Tools Display Modes
  #1  
Old March 16th, 2004, 02:50 PM
Jon Peltier
external usenet poster
 
Posts: n/a
Default Excel VBA method Cells of object _global failed

Two questions:

1) Is Sheets(1) not a worksheet?

2) Does this work:

With Sheetbasis
Set srceRange = .Range(.Cells(2, 2), .Cells(8, 2))
End With

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
http://PeltierTech.com/Excel/Charts/
_______


spoefi wrote:

run time error 1004
Method 'Cells' of object '_global' failed

I try to copy a range from one sheet to another in another workbook.
I get an error on the part where I define my source range (marked with
'XXXX') Why?

Important maybe: the code is in Outlook


Dim Sheettempl As Worksheet
Set Sheettempl =
appExcel1.Workbooks.Open("c:\projects\macros\templ ate.xls").Sheets(1)
Dim Sheetbasis As Worksheet
Set Sheetbasis = appExcel1.Workbooks.Open("c:\projects\macros\test" &
intTeller & ".xls").Sheets(1)


Dim srceRange As Range
Dim destRange As Range

Set srceRange = Sheetbasis.Range(Cells(2, 2), Cells(8, 2)) 'XXXX
Set destRange = Sheettempl.Cells(2, 2)

srceRange.Copy destRange


---
Message posted from http://www.ExcelForum.com/


  #2  
Old March 16th, 2004, 08:20 PM
Tushar Mehta
external usenet poster
 
Posts: n/a
Default Excel VBA method Cells of object _global failed

Set srceRange = Sheetbasis.Range(Cells(2, 2), Cells(8, 2)) 'XXXX

The line above contains an unqualified reference to the Cells property.
If you look up XL VBA help, you will find that XL treats such an
unqualified reference as applying to the ActiveSheet. If the active
sheet is not a worksheet or if it is not the same as Sheetbasis, you
will get an error.

One way to do this would be:

with Sheetbasis
Set srceRange = .Range(.Cells(2, 2), .Cells(8, 2))
end with

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article , spoefi
says...
run time error 1004
Method 'Cells' of object '_global' failed

I try to copy a range from one sheet to another in another workbook.
I get an error on the part where I define my source range (marked with
'XXXX') Why?

Important maybe: the code is in Outlook


Dim Sheettempl As Worksheet
Set Sheettempl =
appExcel1.Workbooks.Open("c:\projects\macros\templ ate.xls").Sheets(1)
Dim Sheetbasis As Worksheet
Set Sheetbasis = appExcel1.Workbooks.Open("c:\projects\macros\test" &
intTeller & ".xls").Sheets(1)


Dim srceRange As Range
Dim destRange As Range

Set srceRange = Sheetbasis.Range(Cells(2, 2), Cells(8, 2)) 'XXXX
Set destRange = Sheettempl.Cells(2, 2)

srceRange.Copy destRange


---
Message posted from http://www.ExcelForum.com/


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


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


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.