Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Compile Error: Invalid use of object

I have the following macro:

Sub LastEdit()

Dim oWB As Workbook
Dim aWB As Workbook
Dim aWS As Worksheet

Set aWB = ActiveWorkbook
Set aWS = ActiveSheet
'May need to change cell values to work for current application. Started at
H originally

Cells(1, "AQ").Value = "Last Author"
Cells(1, "AR").Value = "Creation Date"
Cells(1, "AS").Value = "Last Save Time"
'For i = 2 To Cells(Rows.Count, "A").End(xlUp).Row

For i = 4 To 11
Set oWB = Nothing
Debug.Print Cells(i, "B")
On Error Resume Next
Set oWB = Workbooks.Open(Cells(i, "B"), ReadOnly = True, _
UpdateLinks = False)
On Error GoTo 0
If oWB Is Not Nothing Then
aWS.Range("AQ" & i).Value =
ActiveWorkbook.BuiltinDocumentProperties("Last Author").Value
aWS.Range("AR" & i).Value =
ActiveWorkbook.BuiltinDocumentProperties("Creation Date").Value
aWS.Range("AS" & i).Value =
ActiveWorkbook.BuiltinDocumentProperties("Last Save Time").Value
oWB.Close SaveChanges:=False
aWB.Save
End If
Next i
aWB.Save
End Sub

I get the listed compile error on this line
Set oWB = Workbooks.Open(Cells(i, "B"), ReadOnly = True, _
UpdateLinks = False)

What am I doing wrong?

Thanks,
Barb Reinhardt
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Compile Error: Invalid use of object

You need to change the line

Set oWB = Workbooks.Open(Cells(i, "B"), ReadOnly = True, _
UpdateLinks = False)
to
Set oWB = Workbooks.Open(Cells(i, "B"), ReadOnly:=True, _
UpdateLinks:= False)

Note the colons before the equal signs.

Also, your syntax is wrong on the line
If oWB Is Not Nothing Then
This should be
If Not oWB Is Nothing Then


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Barb Reinhardt" wrote
in message
...
I have the following macro:

Sub LastEdit()

Dim oWB As Workbook
Dim aWB As Workbook
Dim aWS As Worksheet

Set aWB = ActiveWorkbook
Set aWS = ActiveSheet
'May need to change cell values to work for current
application. Started at
H originally

Cells(1, "AQ").Value = "Last Author"
Cells(1, "AR").Value = "Creation Date"
Cells(1, "AS").Value = "Last Save Time"
'For i = 2 To Cells(Rows.Count, "A").End(xlUp).Row

For i = 4 To 11
Set oWB = Nothing
Debug.Print Cells(i, "B")
On Error Resume Next
Set oWB = Workbooks.Open(Cells(i, "B"), ReadOnly = True, _
UpdateLinks = False)
On Error GoTo 0
If oWB Is Not Nothing Then
aWS.Range("AQ" & i).Value =
ActiveWorkbook.BuiltinDocumentProperties("Last Author").Value
aWS.Range("AR" & i).Value =
ActiveWorkbook.BuiltinDocumentProperties("Creation Date").Value
aWS.Range("AS" & i).Value =
ActiveWorkbook.BuiltinDocumentProperties("Last Save
Time").Value
oWB.Close SaveChanges:=False
aWB.Save
End If
Next i
aWB.Save
End Sub

I get the listed compile error on this line
Set oWB = Workbooks.Open(Cells(i, "B"), ReadOnly = True, _
UpdateLinks = False)

What am I doing wrong?

Thanks,
Barb Reinhardt



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Compile Error: Invalid use of object

Thanks for the assist. I have NO IDEA why that changed, because it worked
at one time and I don't remember changing it. Also thanks for the assist
on the syntax.

"Chip Pearson" wrote:

You need to change the line

Set oWB = Workbooks.Open(Cells(i, "B"), ReadOnly = True, _
UpdateLinks = False)
to
Set oWB = Workbooks.Open(Cells(i, "B"), ReadOnly:=True, _
UpdateLinks:= False)

Note the colons before the equal signs.

Also, your syntax is wrong on the line
If oWB Is Not Nothing Then
This should be
If Not oWB Is Nothing Then


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Barb Reinhardt" wrote
in message
...
I have the following macro:

Sub LastEdit()

Dim oWB As Workbook
Dim aWB As Workbook
Dim aWS As Worksheet

Set aWB = ActiveWorkbook
Set aWS = ActiveSheet
'May need to change cell values to work for current
application. Started at
H originally

Cells(1, "AQ").Value = "Last Author"
Cells(1, "AR").Value = "Creation Date"
Cells(1, "AS").Value = "Last Save Time"
'For i = 2 To Cells(Rows.Count, "A").End(xlUp).Row

For i = 4 To 11
Set oWB = Nothing
Debug.Print Cells(i, "B")
On Error Resume Next
Set oWB = Workbooks.Open(Cells(i, "B"), ReadOnly = True, _
UpdateLinks = False)
On Error GoTo 0
If oWB Is Not Nothing Then
aWS.Range("AQ" & i).Value =
ActiveWorkbook.BuiltinDocumentProperties("Last Author").Value
aWS.Range("AR" & i).Value =
ActiveWorkbook.BuiltinDocumentProperties("Creation Date").Value
aWS.Range("AS" & i).Value =
ActiveWorkbook.BuiltinDocumentProperties("Last Save
Time").Value
oWB.Close SaveChanges:=False
aWB.Save
End If
Next i
aWB.Save
End Sub

I get the listed compile error on this line
Set oWB = Workbooks.Open(Cells(i, "B"), ReadOnly = True, _
UpdateLinks = False)

What am I doing wrong?

Thanks,
Barb Reinhardt




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
Compile Error: Wrong arguments or Invalid property Brent E Excel Discussion (Misc queries) 3 May 1st 07 07:11 PM
what does "Compile Error : Invalid Qualifier" mean? funkymonkUK[_157_] Excel Programming 2 May 5th 06 09:48 AM
VBA Help needed -- compile error: object required alexandraVBAgirl Excel Programming 7 February 17th 06 12:55 PM
Compile Error - Wrong number of arguements or invalid property ass James T Excel Programming 2 November 18th 05 07:46 AM
compile error: invalid qualifier. MGG Excel Programming 3 August 2nd 05 04:10 PM


All times are GMT +1. The time now is 12:06 PM.

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

About Us

"It's about Microsoft Excel"