Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Rob Rob is offline
external usenet poster
 
Posts: 234
Default Retain Workbook Name throughout Module

Hi,

I use the below to capture the name of the file that the macro was run from,
this is then used in the Subs code before another Sub is called. My
question is how do I retain the Workbook Name so that I can use in another
Sub within the same module.

iFname = Application.ActiveWorkbook.Name

Thanks, Rob


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,203
Default Retain Workbook Name throughout Module

Define iFname in the declarations portion of the code module (above the first
Sub or Function definition). Do not declare it in any Subs or Functions in
the code module:

Option Explicit
Dim iFname As String

Sub MySub1()
iFname = Application.ActiveWorkbook.Name
End Sub

Sub MySub2()
If iFname="" then
MsgBox "You have not run MySub1 yet"
Else
MsgBox iFname
End if
End Sub

If you need it to be 'visible' across several modules, declare it using
Public instead of Dim.

"Rob" wrote:

Hi,

I use the below to capture the name of the file that the macro was run from,
this is then used in the Subs code before another Sub is called. My
question is how do I retain the Workbook Name so that I can use in another
Sub within the same module.

iFname = Application.ActiveWorkbook.Name

Thanks, Rob


.

  #3   Report Post  
Posted to microsoft.public.excel.programming
Rob Rob is offline
external usenet poster
 
Posts: 234
Default Retain Workbook Name throughout Module

Thank you, couldn't find this in VBA help so much appreciated.

Rob

"JLatham" wrote in message
...
Define iFname in the declarations portion of the code module (above the
first
Sub or Function definition). Do not declare it in any Subs or Functions
in
the code module:

Option Explicit
Dim iFname As String

Sub MySub1()
iFname = Application.ActiveWorkbook.Name
End Sub

Sub MySub2()
If iFname="" then
MsgBox "You have not run MySub1 yet"
Else
MsgBox iFname
End if
End Sub

If you need it to be 'visible' across several modules, declare it using
Public instead of Dim.

"Rob" wrote:

Hi,

I use the below to capture the name of the file that the macro was run
from,
this is then used in the Subs code before another Sub is called. My
question is how do I retain the Workbook Name so that I can use in
another
Sub within the same module.

iFname = Application.ActiveWorkbook.Name

Thanks, Rob


.



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
How to Store Passwords To Multiple Sheets and To Retain thatPasswords When the Workbook IS closed vicky Excel Programming 1 January 22nd 10 09:55 AM
Copy sheet - Break Links to Old Workbook - Retain Formula. Mr Anonymouse Setting up and Configuration of Excel 1 October 15th 05 01:00 AM
Run worksheet module code from workbook module? keithb Excel Programming 1 August 14th 05 04:04 AM
Automatically Delete WorkBook 2 modules by using Workbook 1 module ddiicc Excel Programming 5 July 27th 05 12:53 PM
After Workbook closes all my combo boxes do not retain dropdown list. cwsax Excel Programming 0 November 6th 03 10:25 PM


All times are GMT +1. The time now is 10:52 AM.

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"