variable

gregpet

Board Regular
Joined
Mar 6, 2006
Messages
53
Newbie question. I set a variable name (wbname=thisworkbook.fullname), but when I go to use the variable in a subroutine called right after it is set the debugger says the variable is "empty". What am I doing wrong. Thanks in advance.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Can you post your code, so we can see what is going on?
 
Upvote 0
How did you declare the variable? It needs to be at the top of the module, before any procedures. Then it is public and available to all procedures. Otherwise it is only available to the procedure in which it is declared.
 
Upvote 0
Here is the first part of the code

Private Sub Workbook_Open()
' open workbook startup macro
'
wbname = ThisWorkbook.fullname
wbpath = ThisWorkbook.Path

Sheets(1).Activate
If MsgBox("Good morning ! Would you like to update reports ??", vbYesNo, "") = vbNo Then
Sheets(1).Activate
End
End If

Application.ScreenUpdating = False
Call SheetsVisible
Call showprogress

'MsgBox "estimate dates / move estimate data"
Call copy_batting
Call Estimates2
Sheets(1).Activate
Userform1.CheckBox1.Value = True
DoEvents

then the subroutine where it fails - line windows.(wbname).activate is "empty"

Sub copy_batting()
'Batting Report
Application.ScreenUpdating = False
Windows(wbname).Activate
Sheets("E").Activate
Cells.Select
Selection.ClearContents
Workbooks.Open Filename:= _
wbpath & "batting.xls"
Cells.Select
Selection.Copy
Windows(wbname).Activate
Sheets("E").Select
ActiveSheet.Paste
Range("a1").Select
Application.CutCopyMode = False
Windows("batting.xls").Close
End Sub
 
Upvote 0
If I understand correctly, I needed to dim the variables so they could be used in other sub routines. I added the lines:

Dim wbname As String
Dim wbpath As String

but it still does not work.
 
Upvote 0
You haven't actually declared any variables as far as I can see.:)
 
Upvote 0

Forum statistics

Threads
1,214,980
Messages
6,122,563
Members
449,088
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top