Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi all,
Is it possible to define a variable, to be used in sub / macro?
I have a file path hardcoded in a macro, but if I want this to change, I don't really want to search the script for all instances of it.
I know in SAS, SQL etc...I can use a macro variable & state it at the top. Is this possible with VBScript?
Something like this I want to do:
FilePath = C:\user\document\pictures
Sub
dim fso
Set fso =CreateObject("Scripting.FilesystemObject")
fso.CreateTextFile "FilePath\dummy.txt"
End Sub
Hi Jammy,
Create a variable in front end and assign the variable in inputbox. You can change the path whenever required,
You can use below code to fetch the path from front end variable.
Sub Test
Dim fsoh
FilePath = ActiveDocument.GetVariable("vPath").GetContent.String
FileDate = ActiveDocument.Evaluate("date(Now(), 'DDMMYYYY hhmmss')")
If Right(FilePath,1)<> "\" then
FilePath = FilePath & "\"
End If
Set fso =CreateObject("Scripting.FilesystemObject")
fso.CreateTextFile FilePath & "dummy_" & FileDate & ".txt"
End Sub
Sample attached fro your reference.
Hi Jammy,
Create a variable in front end and assign the variable in inputbox. You can change the path whenever required,
You can use below code to fetch the path from front end variable.
Sub Test
Dim fsoh
FilePath = ActiveDocument.GetVariable("vPath").GetContent.String
FileDate = ActiveDocument.Evaluate("date(Now(), 'DDMMYYYY hhmmss')")
If Right(FilePath,1)<> "\" then
FilePath = FilePath & "\"
End If
Set fso =CreateObject("Scripting.FilesystemObject")
fso.CreateTextFile FilePath & "dummy_" & FileDate & ".txt"
End Sub
Sample attached fro your reference.
If you want to hardcode the path use below code.
FilePath = "C:\user\document\pictures"
Sub Test
Dim fso
Set fso =CreateObject("Scripting.FilesystemObject")
fso.CreateTextFile FilePath & "\Dummy.txt"
End Sub
Thank you..... perfect solution & I got it working!