cannot identify Workbook as object variable
up vote
-1
down vote
favorite
I'm building an automated request form and am running into a headache that only triggers for other users. 3 others receive a run-time error and I cannot figure out what is going on as I've used basically this same script in other books without ever having an issue reported.
Sub tracker_upload()
ActiveWindow.ScrollRow = 1
Run "processing" 'basic UF to display status
With Application
.ScreenUpdating = False
.DisplayAlerts = False
End With
Run "archive" 'saves completed form to a SP folder
With WaitForm
.lbStatus.Caption = "...archiving form to shared drive"
.Repaint
End With
Application.Wait (Now + TimeValue("00:00:02"))
With Form
If .Priority_Critical_YN = True Then
p = "Critical"
ElseIf .Priority_Must_Have_YN = True Then
p = "High"
ElseIf .Priority_Need_YN = True Then
p = "Medium"
ElseIf .Priority_Nice_YN = True Then
p = "Low"
End If
.Shapes("upload").Visible = False
End With
With Range("tbData")
uID = .Cells(1).Value
.Cells(2) = "New"
.Cells(3) = p
.Cells(9) = Environ$("UserName")
.Cells(10) = Date
.Hyperlinks.Add .Cells(1), ThisWorkbook.FullName, TextToDisplay:=uID
End With
With WaitForm
.lbStatus.Caption = "...updating tracker information"
.Repaint
End With
Dim wb1 As Workbook, wb2 As Workbook
On Error Resume Next
Set wb1 = ActiveWorkbook
Set wb2 = Workbooks("Requests Tracker")
'detect if workbook is already open and open if not
If wb2 Is Nothing Then
Application.Workbooks.Open ("My Shared Drive LocationRequests Tracker.xlsx"), ignorereadonlyrecommended = True
Set wb2 = Workbooks("Requests Tracker")
End If
On Error GoTo 0
wb1.Sheets("data").Range("tbData").Copy
With wb2
.Activate
With .Sheets("Requests")
If .Range("tbTracker").Cells(1) = "" Then
lastrow = .Range("A" & Rows.Count).End(xlUp).Row
Else: lastrow = .Range("A" & Rows.Count).End(xlUp).Row + 1
End If
.Range("A" & lastrow).PasteSpecial xlPasteAllUsingSourceTheme
.Columns.AutoFit
End With
.Save
.Close True
End With
Set wb2 = Nothing
On Error GoTo 0
With Application
.CutCopyMode = False
.ScreenUpdating = True
.DisplayAlerts = True
.Wait (Now + TimeValue("00:00:02"))
End With
Unload WaitForm
wb1.Save
mb = MsgBox("This request has been successfully recorded on the Tracker" & vbCrLf _
& vbCrLf _
& "The form will now close, would you like to open the tracker now?", vbYesNo + vbInformation, "completed")
If mb = vbYes Then
Application.Workbooks.Open ("My Shared Drive LocationRequests Tracker.xlsx"), ignorereadonlyrecommended = True
End If
If Application.Windows.Count = 1 Then
wb1.Saved = True
Application.Quit
Else: wb1.Close False
End If
End Sub
initially it was getting hung up on the .Sheets("Requests")
line, then the line below it. It was the decimal in front of each, which I found really bizarre as I've never come across this before. Sure enough, after leaving the .Save
and .Close True
with decimals, it triggered another error on the next function preceded by a decimal as shown below.
UPDATE: I parsed out the bit of code where I set wb1
and wb2
as I identified it was wb2
that was giving the user an error. I did some testing with several other users who had no issue setting & identifying wb2
as Workbooks("Requests Tracker")
. I finally got the sub to pass by adding the file extension to the end of the Workbook
name. Why would this be required for this user only?
excel vba excel-vba
|
show 10 more comments
up vote
-1
down vote
favorite
I'm building an automated request form and am running into a headache that only triggers for other users. 3 others receive a run-time error and I cannot figure out what is going on as I've used basically this same script in other books without ever having an issue reported.
Sub tracker_upload()
ActiveWindow.ScrollRow = 1
Run "processing" 'basic UF to display status
With Application
.ScreenUpdating = False
.DisplayAlerts = False
End With
Run "archive" 'saves completed form to a SP folder
With WaitForm
.lbStatus.Caption = "...archiving form to shared drive"
.Repaint
End With
Application.Wait (Now + TimeValue("00:00:02"))
With Form
If .Priority_Critical_YN = True Then
p = "Critical"
ElseIf .Priority_Must_Have_YN = True Then
p = "High"
ElseIf .Priority_Need_YN = True Then
p = "Medium"
ElseIf .Priority_Nice_YN = True Then
p = "Low"
End If
.Shapes("upload").Visible = False
End With
With Range("tbData")
uID = .Cells(1).Value
.Cells(2) = "New"
.Cells(3) = p
.Cells(9) = Environ$("UserName")
.Cells(10) = Date
.Hyperlinks.Add .Cells(1), ThisWorkbook.FullName, TextToDisplay:=uID
End With
With WaitForm
.lbStatus.Caption = "...updating tracker information"
.Repaint
End With
Dim wb1 As Workbook, wb2 As Workbook
On Error Resume Next
Set wb1 = ActiveWorkbook
Set wb2 = Workbooks("Requests Tracker")
'detect if workbook is already open and open if not
If wb2 Is Nothing Then
Application.Workbooks.Open ("My Shared Drive LocationRequests Tracker.xlsx"), ignorereadonlyrecommended = True
Set wb2 = Workbooks("Requests Tracker")
End If
On Error GoTo 0
wb1.Sheets("data").Range("tbData").Copy
With wb2
.Activate
With .Sheets("Requests")
If .Range("tbTracker").Cells(1) = "" Then
lastrow = .Range("A" & Rows.Count).End(xlUp).Row
Else: lastrow = .Range("A" & Rows.Count).End(xlUp).Row + 1
End If
.Range("A" & lastrow).PasteSpecial xlPasteAllUsingSourceTheme
.Columns.AutoFit
End With
.Save
.Close True
End With
Set wb2 = Nothing
On Error GoTo 0
With Application
.CutCopyMode = False
.ScreenUpdating = True
.DisplayAlerts = True
.Wait (Now + TimeValue("00:00:02"))
End With
Unload WaitForm
wb1.Save
mb = MsgBox("This request has been successfully recorded on the Tracker" & vbCrLf _
& vbCrLf _
& "The form will now close, would you like to open the tracker now?", vbYesNo + vbInformation, "completed")
If mb = vbYes Then
Application.Workbooks.Open ("My Shared Drive LocationRequests Tracker.xlsx"), ignorereadonlyrecommended = True
End If
If Application.Windows.Count = 1 Then
wb1.Saved = True
Application.Quit
Else: wb1.Close False
End If
End Sub
initially it was getting hung up on the .Sheets("Requests")
line, then the line below it. It was the decimal in front of each, which I found really bizarre as I've never come across this before. Sure enough, after leaving the .Save
and .Close True
with decimals, it triggered another error on the next function preceded by a decimal as shown below.
UPDATE: I parsed out the bit of code where I set wb1
and wb2
as I identified it was wb2
that was giving the user an error. I did some testing with several other users who had no issue setting & identifying wb2
as Workbooks("Requests Tracker")
. I finally got the sub to pass by adding the file extension to the end of the Workbook
name. Why would this be required for this user only?
excel vba excel-vba
4
Please include your code rather than a screenshot of your code.
– TylerH
Nov 8 at 19:40
1
If you do not know that you are not supposed to post photos of your code, my guess is that you have also not made an attempt to browse this site for a potential solution...
– urdearboy
Nov 8 at 19:41
@TylerH code added.
– Awill
Nov 8 at 21:28
1
Do you havewb2
set?
– Davesexcel
Nov 9 at 12:50
1
It was the decimal in front of each, which I found really bizarre as I've never come across this before
- so you "fixed" the problem by making your code call the current worksheet/worksheet'sActivate
instead ofwb2.Activate
, and then you did not know how to fix.Save
? Please put the.
back, read about theWith
clause, and make surewb2
is initialized.
– GSerg
Nov 9 at 21:04
|
show 10 more comments
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I'm building an automated request form and am running into a headache that only triggers for other users. 3 others receive a run-time error and I cannot figure out what is going on as I've used basically this same script in other books without ever having an issue reported.
Sub tracker_upload()
ActiveWindow.ScrollRow = 1
Run "processing" 'basic UF to display status
With Application
.ScreenUpdating = False
.DisplayAlerts = False
End With
Run "archive" 'saves completed form to a SP folder
With WaitForm
.lbStatus.Caption = "...archiving form to shared drive"
.Repaint
End With
Application.Wait (Now + TimeValue("00:00:02"))
With Form
If .Priority_Critical_YN = True Then
p = "Critical"
ElseIf .Priority_Must_Have_YN = True Then
p = "High"
ElseIf .Priority_Need_YN = True Then
p = "Medium"
ElseIf .Priority_Nice_YN = True Then
p = "Low"
End If
.Shapes("upload").Visible = False
End With
With Range("tbData")
uID = .Cells(1).Value
.Cells(2) = "New"
.Cells(3) = p
.Cells(9) = Environ$("UserName")
.Cells(10) = Date
.Hyperlinks.Add .Cells(1), ThisWorkbook.FullName, TextToDisplay:=uID
End With
With WaitForm
.lbStatus.Caption = "...updating tracker information"
.Repaint
End With
Dim wb1 As Workbook, wb2 As Workbook
On Error Resume Next
Set wb1 = ActiveWorkbook
Set wb2 = Workbooks("Requests Tracker")
'detect if workbook is already open and open if not
If wb2 Is Nothing Then
Application.Workbooks.Open ("My Shared Drive LocationRequests Tracker.xlsx"), ignorereadonlyrecommended = True
Set wb2 = Workbooks("Requests Tracker")
End If
On Error GoTo 0
wb1.Sheets("data").Range("tbData").Copy
With wb2
.Activate
With .Sheets("Requests")
If .Range("tbTracker").Cells(1) = "" Then
lastrow = .Range("A" & Rows.Count).End(xlUp).Row
Else: lastrow = .Range("A" & Rows.Count).End(xlUp).Row + 1
End If
.Range("A" & lastrow).PasteSpecial xlPasteAllUsingSourceTheme
.Columns.AutoFit
End With
.Save
.Close True
End With
Set wb2 = Nothing
On Error GoTo 0
With Application
.CutCopyMode = False
.ScreenUpdating = True
.DisplayAlerts = True
.Wait (Now + TimeValue("00:00:02"))
End With
Unload WaitForm
wb1.Save
mb = MsgBox("This request has been successfully recorded on the Tracker" & vbCrLf _
& vbCrLf _
& "The form will now close, would you like to open the tracker now?", vbYesNo + vbInformation, "completed")
If mb = vbYes Then
Application.Workbooks.Open ("My Shared Drive LocationRequests Tracker.xlsx"), ignorereadonlyrecommended = True
End If
If Application.Windows.Count = 1 Then
wb1.Saved = True
Application.Quit
Else: wb1.Close False
End If
End Sub
initially it was getting hung up on the .Sheets("Requests")
line, then the line below it. It was the decimal in front of each, which I found really bizarre as I've never come across this before. Sure enough, after leaving the .Save
and .Close True
with decimals, it triggered another error on the next function preceded by a decimal as shown below.
UPDATE: I parsed out the bit of code where I set wb1
and wb2
as I identified it was wb2
that was giving the user an error. I did some testing with several other users who had no issue setting & identifying wb2
as Workbooks("Requests Tracker")
. I finally got the sub to pass by adding the file extension to the end of the Workbook
name. Why would this be required for this user only?
excel vba excel-vba
I'm building an automated request form and am running into a headache that only triggers for other users. 3 others receive a run-time error and I cannot figure out what is going on as I've used basically this same script in other books without ever having an issue reported.
Sub tracker_upload()
ActiveWindow.ScrollRow = 1
Run "processing" 'basic UF to display status
With Application
.ScreenUpdating = False
.DisplayAlerts = False
End With
Run "archive" 'saves completed form to a SP folder
With WaitForm
.lbStatus.Caption = "...archiving form to shared drive"
.Repaint
End With
Application.Wait (Now + TimeValue("00:00:02"))
With Form
If .Priority_Critical_YN = True Then
p = "Critical"
ElseIf .Priority_Must_Have_YN = True Then
p = "High"
ElseIf .Priority_Need_YN = True Then
p = "Medium"
ElseIf .Priority_Nice_YN = True Then
p = "Low"
End If
.Shapes("upload").Visible = False
End With
With Range("tbData")
uID = .Cells(1).Value
.Cells(2) = "New"
.Cells(3) = p
.Cells(9) = Environ$("UserName")
.Cells(10) = Date
.Hyperlinks.Add .Cells(1), ThisWorkbook.FullName, TextToDisplay:=uID
End With
With WaitForm
.lbStatus.Caption = "...updating tracker information"
.Repaint
End With
Dim wb1 As Workbook, wb2 As Workbook
On Error Resume Next
Set wb1 = ActiveWorkbook
Set wb2 = Workbooks("Requests Tracker")
'detect if workbook is already open and open if not
If wb2 Is Nothing Then
Application.Workbooks.Open ("My Shared Drive LocationRequests Tracker.xlsx"), ignorereadonlyrecommended = True
Set wb2 = Workbooks("Requests Tracker")
End If
On Error GoTo 0
wb1.Sheets("data").Range("tbData").Copy
With wb2
.Activate
With .Sheets("Requests")
If .Range("tbTracker").Cells(1) = "" Then
lastrow = .Range("A" & Rows.Count).End(xlUp).Row
Else: lastrow = .Range("A" & Rows.Count).End(xlUp).Row + 1
End If
.Range("A" & lastrow).PasteSpecial xlPasteAllUsingSourceTheme
.Columns.AutoFit
End With
.Save
.Close True
End With
Set wb2 = Nothing
On Error GoTo 0
With Application
.CutCopyMode = False
.ScreenUpdating = True
.DisplayAlerts = True
.Wait (Now + TimeValue("00:00:02"))
End With
Unload WaitForm
wb1.Save
mb = MsgBox("This request has been successfully recorded on the Tracker" & vbCrLf _
& vbCrLf _
& "The form will now close, would you like to open the tracker now?", vbYesNo + vbInformation, "completed")
If mb = vbYes Then
Application.Workbooks.Open ("My Shared Drive LocationRequests Tracker.xlsx"), ignorereadonlyrecommended = True
End If
If Application.Windows.Count = 1 Then
wb1.Saved = True
Application.Quit
Else: wb1.Close False
End If
End Sub
initially it was getting hung up on the .Sheets("Requests")
line, then the line below it. It was the decimal in front of each, which I found really bizarre as I've never come across this before. Sure enough, after leaving the .Save
and .Close True
with decimals, it triggered another error on the next function preceded by a decimal as shown below.
UPDATE: I parsed out the bit of code where I set wb1
and wb2
as I identified it was wb2
that was giving the user an error. I did some testing with several other users who had no issue setting & identifying wb2
as Workbooks("Requests Tracker")
. I finally got the sub to pass by adding the file extension to the end of the Workbook
name. Why would this be required for this user only?
excel vba excel-vba
excel vba excel-vba
edited yesterday
asked Nov 8 at 19:36
Awill
5713
5713
4
Please include your code rather than a screenshot of your code.
– TylerH
Nov 8 at 19:40
1
If you do not know that you are not supposed to post photos of your code, my guess is that you have also not made an attempt to browse this site for a potential solution...
– urdearboy
Nov 8 at 19:41
@TylerH code added.
– Awill
Nov 8 at 21:28
1
Do you havewb2
set?
– Davesexcel
Nov 9 at 12:50
1
It was the decimal in front of each, which I found really bizarre as I've never come across this before
- so you "fixed" the problem by making your code call the current worksheet/worksheet'sActivate
instead ofwb2.Activate
, and then you did not know how to fix.Save
? Please put the.
back, read about theWith
clause, and make surewb2
is initialized.
– GSerg
Nov 9 at 21:04
|
show 10 more comments
4
Please include your code rather than a screenshot of your code.
– TylerH
Nov 8 at 19:40
1
If you do not know that you are not supposed to post photos of your code, my guess is that you have also not made an attempt to browse this site for a potential solution...
– urdearboy
Nov 8 at 19:41
@TylerH code added.
– Awill
Nov 8 at 21:28
1
Do you havewb2
set?
– Davesexcel
Nov 9 at 12:50
1
It was the decimal in front of each, which I found really bizarre as I've never come across this before
- so you "fixed" the problem by making your code call the current worksheet/worksheet'sActivate
instead ofwb2.Activate
, and then you did not know how to fix.Save
? Please put the.
back, read about theWith
clause, and make surewb2
is initialized.
– GSerg
Nov 9 at 21:04
4
4
Please include your code rather than a screenshot of your code.
– TylerH
Nov 8 at 19:40
Please include your code rather than a screenshot of your code.
– TylerH
Nov 8 at 19:40
1
1
If you do not know that you are not supposed to post photos of your code, my guess is that you have also not made an attempt to browse this site for a potential solution...
– urdearboy
Nov 8 at 19:41
If you do not know that you are not supposed to post photos of your code, my guess is that you have also not made an attempt to browse this site for a potential solution...
– urdearboy
Nov 8 at 19:41
@TylerH code added.
– Awill
Nov 8 at 21:28
@TylerH code added.
– Awill
Nov 8 at 21:28
1
1
Do you have
wb2
set?– Davesexcel
Nov 9 at 12:50
Do you have
wb2
set?– Davesexcel
Nov 9 at 12:50
1
1
It was the decimal in front of each, which I found really bizarre as I've never come across this before
- so you "fixed" the problem by making your code call the current worksheet/worksheet's Activate
instead of wb2.Activate
, and then you did not know how to fix .Save
? Please put the .
back, read about the With
clause, and make sure wb2
is initialized.– GSerg
Nov 9 at 21:04
It was the decimal in front of each, which I found really bizarre as I've never come across this before
- so you "fixed" the problem by making your code call the current worksheet/worksheet's Activate
instead of wb2.Activate
, and then you did not know how to fix .Save
? Please put the .
back, read about the With
clause, and make sure wb2
is initialized.– GSerg
Nov 9 at 21:04
|
show 10 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53214946%2fcannot-identify-workbook-as-object-variable%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
4
Please include your code rather than a screenshot of your code.
– TylerH
Nov 8 at 19:40
1
If you do not know that you are not supposed to post photos of your code, my guess is that you have also not made an attempt to browse this site for a potential solution...
– urdearboy
Nov 8 at 19:41
@TylerH code added.
– Awill
Nov 8 at 21:28
1
Do you have
wb2
set?– Davesexcel
Nov 9 at 12:50
1
It was the decimal in front of each, which I found really bizarre as I've never come across this before
- so you "fixed" the problem by making your code call the current worksheet/worksheet'sActivate
instead ofwb2.Activate
, and then you did not know how to fix.Save
? Please put the.
back, read about theWith
clause, and make surewb2
is initialized.– GSerg
Nov 9 at 21:04