PC Review


Reply
Thread Tools Rate Thread

Auto_Open and global variable

 
 
VBA beginner
Guest
Posts: n/a
 
      15th Sep 2008
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?


 
Reply With Quote
 
 
 
 
Gary Keramidas
Guest
Posts: n/a
 
      15th Sep 2008
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" <(E-Mail Removed)> wrote in message
news:802D9FE7-F54F-4EDD-AE75-(E-Mail Removed)...
>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?
>
>



 
Reply With Quote
 
Gary Keramidas
Guest
Posts: n/a
 
      15th Sep 2008
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
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:802D9FE7-F54F-4EDD-AE75-(E-Mail Removed)...
>>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?
>>
>>

>
>



 
Reply With Quote
 
VBA beginner
Guest
Posts: n/a
 
      15th Sep 2008
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
> news:(E-Mail Removed)...
> > 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" <(E-Mail Removed)> wrote in message
> > news:802D9FE7-F54F-4EDD-AE75-(E-Mail Removed)...
> >>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?
> >>
> >>

> >
> >

>
>
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      15th Sep 2008
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
> > news:(E-Mail Removed)...
> > > 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" <(E-Mail Removed)> wrote in message
> > > news:802D9FE7-F54F-4EDD-AE75-(E-Mail Removed)...
> > >>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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PASSING VARIABLE TO .xlT FILE FROM .xlA FILE (CONTAINS 'Auto_Open' PROCEDURE) Chuckles123 Microsoft Excel Programming 0 9th Sep 2005 07:31 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 Microsoft Excel Worksheet Functions 1 9th Jul 2005 03:05 AM
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 Microsoft Excel Discussion 1 9th Jul 2005 01:04 AM
how to set a 'global' variable in global.asax Jason Shohet Microsoft C# .NET 2 19th Apr 2004 08:43 PM
Auto_open and environ variable error cannot find library Philippe Cand Microsoft Excel Programming 2 6th Mar 2004 12:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:35 AM.