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?










share|improve this question




















  • 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'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















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?










share|improve this question




















  • 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'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













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?










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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'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














  • 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'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








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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

Schultheiß

Verwaltungsgliederung Dänemarks

Liste der Kulturdenkmale in Wilsdruff