Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Auto_Open and global variable

I have tried to save the name of the opened file to variable, so that I can
use it in other modules and worksheets. I have the following auto_open sub:


Sub auto_open()
Global filename As Variant
filename = Application.ThisWorkbook.Name

End Sub

This doesn't work, I have the Compile error message: Invalid attribute in
Sub or Function. Auto_open sub in the module, so what is wrong in this code?
Or is there any other way to do this?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Auto_Open and global variable

try this, but i usually put all of the public variables in a separate module

Option Explicit
Public filename As String
Sub auto_open()

filename = Application.ThisWorkbook.Name

End Sub



--


Gary


"VBA beginner" wrote in message
...
I have tried to save the name of the opened file to variable, so that I can
use it in other modules and worksheets. I have the following auto_open sub:


Sub auto_open()
Global filename As Variant
filename = Application.ThisWorkbook.Name

End Sub

This doesn't work, I have the Compile error message: Invalid attribute in
Sub or Function. Auto_open sub in the module, so what is wrong in this code?
Or is there any other way to do this?




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Auto_Open and global variable

oh, and don't use filename, use fname or some other variant. filename is valid
property name in vba.

--


Gary


"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
try this, but i usually put all of the public variables in a separate module

Option Explicit
Public filename As String
Sub auto_open()

filename = Application.ThisWorkbook.Name

End Sub



--


Gary


"VBA beginner" wrote in message
...
I have tried to save the name of the opened file to variable, so that I can
use it in other modules and worksheets. I have the following auto_open sub:


Sub auto_open()
Global filename As Variant
filename = Application.ThisWorkbook.Name

End Sub

This doesn't work, I have the Compile error message: Invalid attribute in
Sub or Function. Auto_open sub in the module, so what is wrong in this code?
Or is there any other way to do this?






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Auto_Open and global variable

Unfortunately I can't make this work. I have this public variable in separate
module and still the value of the fname variable is empty in the other
module.

"Gary Keramidas" kirjoitti:

oh, and don't use filename, use fname or some other variant. filename is valid
property name in vba.

--


Gary


"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
try this, but i usually put all of the public variables in a separate module

Option Explicit
Public filename As String
Sub auto_open()

filename = Application.ThisWorkbook.Name

End Sub



--


Gary


"VBA beginner" wrote in message
...
I have tried to save the name of the opened file to variable, so that I can
use it in other modules and worksheets. I have the following auto_open sub:


Sub auto_open()
Global filename As Variant
filename = Application.ThisWorkbook.Name

End Sub

This doesn't work, I have the Compile error message: Invalid attribute in
Sub or Function. Auto_open sub in the module, so what is wrong in this code?
Or is there any other way to do this?







  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Auto_Open and global variable

Did you run the Auto_Open procedure after you made a change to your code?

If no, then run that Auto_Open. Then do some experimentation with your other
procedure.

ps. I hope that this is a learning exercise. You'd really want to use
ThisWorkbook.Name in other procedures.



VBA beginner wrote:

Unfortunately I can't make this work. I have this public variable in separate
module and still the value of the fname variable is empty in the other
module.

"Gary Keramidas" kirjoitti:

oh, and don't use filename, use fname or some other variant. filename is valid
property name in vba.

--


Gary


"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
try this, but i usually put all of the public variables in a separate module

Option Explicit
Public filename As String
Sub auto_open()

filename = Application.ThisWorkbook.Name

End Sub



--


Gary


"VBA beginner" wrote in message
...
I have tried to save the name of the opened file to variable, so that I can
use it in other modules and worksheets. I have the following auto_open sub:


Sub auto_open()
Global filename As Variant
filename = Application.ThisWorkbook.Name

End Sub

This doesn't work, I have the Compile error message: Invalid attribute in
Sub or Function. Auto_open sub in the module, so what is wrong in this code?
Or is there any other way to do this?








--

Dave Peterson
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
Global variable dhstein Excel Discussion (Misc queries) 2 October 30th 09 01:03 PM
Global Variable dhstein Excel Discussion (Misc queries) 4 July 26th 09 05:10 PM
Global Variable Francis Brown Excel Programming 4 November 27th 05 06:38 PM
why is it saying sheetcnt is "variable not defined" how to do a global variable to share over multiple functions in vba for excel? Daniel Excel Worksheet Functions 1 July 9th 05 03:05 AM
Auto_open and environ variable error cannot find library Philippe Cand[_2_] Excel Programming 2 March 6th 04 12:26 PM


All times are GMT +1. The time now is 09:19 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"