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

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
58,945
Office Version
  1. 365
Platform
  1. Windows
Can you post your code, so we can see what is going on?
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
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.
 

gregpet

Board Regular
Joined
Mar 6, 2006
Messages
53
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
 

gregpet

Board Regular
Joined
Mar 6, 2006
Messages
53
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.
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,303
Office Version
  1. 365
Platform
  1. Windows
You haven't actually declared any variables as far as I can see.:)
 

Forum statistics

Threads
1,141,017
Messages
5,703,752
Members
421,313
Latest member
Mooncake1

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
Top