Passing variables from VBA to VBScript

keith0528

Active Member
Joined
Apr 23, 2009
Messages
250
Greetings,

I have a line of code in my excel vba code that calls to a VBScript:

Shell "wscript C:\Users\kev\Documents\VBScript_Stuff\Copy_File_to_Splitter.vbs"

I want the VBScript to receive a variable "sFile" a string, which contains a file name and add that to the file path in VBScript. The VBScript exists outside of the VBA code.

vbscript:
Set objFSO = CreateObject("Scripting.FileSystemObject")
FileSystemObject.CopyFile "\\abc\LoMo\ImportFileLoadingDock\KeLance\" & TodaysFolder & "\" & sFile, "destination path"

I've searched the message boards but haven't found anything that fits the bill. Does anyone have knowledge of how to do this?

thanks,
Keith
 
I forgot to mention the date type variable: TodaysFolder = Format(VBA.Date(), "YYYYMMDD") this is used as argument 0
Shell "wscript C:\Users\klxxx\Documents\VBScript_Stuff\Copy_File_to_Splitter.vbs" & " {TodaysFolder}" & " {sFile1}"


thanks,
Keith
 
Upvote 0

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Try this:
Code:
Sub vba()
    Const Q = """"
    Dim TodaysFolder As String, sFile1 As String
    TodaysFolder = Format(Date, "YYYYMMDD")
    sFile1 = "BAxxx_xx_03202013.xlsx"   'hard-coded file name for testing
    
    Shell "wscript ""C:\Users\kev\Documents\VBScript_Stuff\Copy_File_to_Splitter.vbs"" " & Q & TodaysFolder & Q & " " & Q & sFile1 & Q
End Sub
Code:
'Copy_File_to_Splitter.vbs
MsgBox ">" & WScript.Arguments(0) & "<" & vbNewLine & ">" & WScript.Arguments(1) & "<"
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile "\\abcdef\LoanMods\ImportFileLoadingDock\KeithLxxxxxxx\" & WScript.Arguments(0) & "\" & WScript.Arguments(1), _
			    "\\abcdef\loanmods\ImportFileLoadingDock\LMWDENSplitter\" & WScript.Arguments(1)
 
Upvote 0

Forum statistics

Threads
1,215,477
Messages
6,125,031
Members
449,205
Latest member
Eggy66

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top