Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 103
Default Object doesn't support this method

Hi All,

I have got a problem with my code - below is an extract. It gets stuck on "
Set myBook = Workbooks.Open(SRCbook)" stating "Object deosn't support this
method". I can't work out why?

Sub Import_data_from_Project_Log()
Dim basebook As Workbook
Dim SRCbook As String
'Dim DSTbook As Workbook
Dim myBook As Workbook
Dim rngSource(2) As Range
Dim rngDest(2) As Range
Dim sourceRNG 'As Range
Dim destRNG 'As Range

SRCbook = "C:\Documents and Settings\temp\SMVIL Project Log.xls"
Set basebook = ThisWorkbook
Set rngSource(1) = Worksheets("Project Log Form").Range("A8:U79")
Set rngSource(2) = Worksheets("Risk Management Plan").Range("A7:X10")


For i = 1 To UBound(rngSource)



Set myBook = Workbooks.Open(SRCbook)

Set sourceRNG = myBook.rngSource(i)

Next i

End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default Object doesn't support this method

I have never had any luck setting a workbook object to a workbook that is not
open yet. First you open and then you set, something like this...

Workbooks.Open(SRCbook)
Set myBook = activeworkbook

If there is a better way I would love to know it, but in the absence of a
better solution the above works.
--
HTH...

Jim Thomlinson


"Andibevan" wrote:

Hi All,

I have got a problem with my code - below is an extract. It gets stuck on "
Set myBook = Workbooks.Open(SRCbook)" stating "Object deosn't support this
method". I can't work out why?

Sub Import_data_from_Project_Log()
Dim basebook As Workbook
Dim SRCbook As String
'Dim DSTbook As Workbook
Dim myBook As Workbook
Dim rngSource(2) As Range
Dim rngDest(2) As Range
Dim sourceRNG 'As Range
Dim destRNG 'As Range

SRCbook = "C:\Documents and Settings\temp\SMVIL Project Log.xls"
Set basebook = ThisWorkbook
Set rngSource(1) = Worksheets("Project Log Form").Range("A8:U79")
Set rngSource(2) = Worksheets("Risk Management Plan").Range("A7:X10")


For i = 1 To UBound(rngSource)



Set myBook = Workbooks.Open(SRCbook)

Set sourceRNG = myBook.rngSource(i)

Next i

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 103
Default Object doesn't support this method

Thanks for the advice - It's an interesting problem bearing in mind that the
same approach DOES work when adding and handling individual worksheets.

"Jim Thomlinson" wrote in message
...
I have never had any luck setting a workbook object to a workbook that is

not
open yet. First you open and then you set, something like this...

Workbooks.Open(SRCbook)
Set myBook = activeworkbook

If there is a better way I would love to know it, but in the absence of a
better solution the above works.
--
HTH...

Jim Thomlinson


"Andibevan" wrote:

Hi All,

I have got a problem with my code - below is an extract. It gets stuck

on "
Set myBook = Workbooks.Open(SRCbook)" stating "Object deosn't support

this
method". I can't work out why?

Sub Import_data_from_Project_Log()
Dim basebook As Workbook
Dim SRCbook As String
'Dim DSTbook As Workbook
Dim myBook As Workbook
Dim rngSource(2) As Range
Dim rngDest(2) As Range
Dim sourceRNG 'As Range
Dim destRNG 'As Range

SRCbook = "C:\Documents and Settings\temp\SMVIL Project Log.xls"
Set basebook = ThisWorkbook
Set rngSource(1) = Worksheets("Project Log Form").Range("A8:U79")
Set rngSource(2) = Worksheets("Risk Management Plan").Range("A7:X10")


For i = 1 To UBound(rngSource)



Set myBook = Workbooks.Open(SRCbook)

Set sourceRNG = myBook.rngSource(i)

Next i

End Sub





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 103
Default Object doesn't support this method

Actually Jim, You may want to take a look at the following code that offers
one method of achieving what you want:-

mybook gets declared as a workbook then it gets used as follows:-

Set mybook = Workbooks.Open(.FoundFiles(i))
Set sourceRange = mybook.Worksheets(1).Range("a1:c5")

I was trying to use an array instead of "Worksheets(1).Range("a1:c5")" -
doesn't seem to be possible????

Sub CopyRange()
Dim basebook As Workbook
Dim mybook As Workbook
Dim sourceRange As Range
Dim destrange As Range
Dim rnum As Long
Dim i As Long
Dim a As Long
Application.ScreenUpdating = False
With Application.FileSearch
.NewSearch
.LookIn = "C:\Data"
.SearchSubFolders = False
.FileType = msoFileTypeExcelWorkbooks
If .Execute() 0 Then
Set basebook = ThisWorkbook
rnum = 1
For i = 1 To .FoundFiles.Count
Set mybook = Workbooks.Open(.FoundFiles(i))
Set sourceRange = mybook.Worksheets(1).Range("a1:c5")
a = sourceRange.Rows.Count
Set destrange = basebook.Worksheets(1).Cells(rnum, 1)
sourceRange.Copy destrange
mybook.Close
rnum = i * a + 1
Next i
End If
End With
Application.ScreenUpdating = True
End Sub


"Jim Thomlinson" wrote in message
...
I have never had any luck setting a workbook object to a workbook that is

not
open yet. First you open and then you set, something like this...

Workbooks.Open(SRCbook)
Set myBook = activeworkbook

If there is a better way I would love to know it, but in the absence of a
better solution the above works.
--
HTH...

Jim Thomlinson


"Andibevan" wrote:

Hi All,

I have got a problem with my code - below is an extract. It gets stuck

on "
Set myBook = Workbooks.Open(SRCbook)" stating "Object deosn't support

this
method". I can't work out why?

Sub Import_data_from_Project_Log()
Dim basebook As Workbook
Dim SRCbook As String
'Dim DSTbook As Workbook
Dim myBook As Workbook
Dim rngSource(2) As Range
Dim rngDest(2) As Range
Dim sourceRNG 'As Range
Dim destRNG 'As Range

SRCbook = "C:\Documents and Settings\temp\SMVIL Project Log.xls"
Set basebook = ThisWorkbook
Set rngSource(1) = Worksheets("Project Log Form").Range("A8:U79")
Set rngSource(2) = Worksheets("Risk Management Plan").Range("A7:X10")


For i = 1 To UBound(rngSource)



Set myBook = Workbooks.Open(SRCbook)

Set sourceRNG = myBook.rngSource(i)

Next i

End Sub





Reply
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
runtime error 434, object does not support this method or property Janis Excel Discussion (Misc queries) 4 January 17th 08 04:10 PM
object reference does not support this property or method [email protected] Excel Discussion (Misc queries) 2 June 14th 06 07:23 PM
Object doesn't support this property or method (Error 438) Kiran Excel Discussion (Misc queries) 1 July 12th 05 08:42 PM
Object doesn't support this property or method davegb Excel Programming 11 May 12th 05 03:36 PM
Object doesn't support this property or method Rick Campbell Excel Programming 2 July 13th 03 11:53 PM


All times are GMT +1. The time now is 12:11 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"