Active Excel file name in VB

Solved
alain5906 Posted messages 69 Status Membre -  
alain5906 Posted messages 69 Status Membre -
Hello,
Hello,
I have Office 2000 running on Vista.
I can't seem to assign a macro to a specific file, even when specifying "for this workbook" during its creation.
So I thought about using an add-in in Visual Basic for the specific macro, but how do I specify the name of the file I'm working on in VB?
Thank you for your help
Configuration: Windows Vista Internet Explorer 7.0

3 réponses

greenthumb
 
Hello,

with thisworkbook.path maybe? ;)
1
alain5906 Posted messages 69 Status Membre 6
 
No, I tried declaring after the Sub macro: thisworkbook = activeworkbook
then: If thisworkbook = "nomfichier.xls"
(execute macro)
else
end sub

result syntax error on the IF line

I'm not at all familiar with the VB language. I only know how to modify macros during their execution.
Thank you for your help.
0
greenthumb > alain5906 Posted messages 69 Status Membre
 
So,

First, to create an IF statement, the structure is as follows:

IF conditions THEN
(code)
ELSE 'optional
(other code)
END IF

Next, you cannot compare thisworkbook with a string:

thisworkbook.path, however, can be compared with a string. However, be careful, thisworkbook.path returns the full path of your file (e.g., "C:/Documents And Settings/Toto/tata.xls"), but it's the only method I know to get the name of the file :S
0