Reputation: 1
I'm working on making a simple application in VB.Net that allows the user to select a file, then it will format it and place the file in the correct destination, thereby making a repetitive process much less tedious. I have it working in VBA with Excel, but I'd rather have my own standalone application. I don't need Excel to manipulate the information in any way. However, it creates an error when I hit the 'execute' button. So this is my working code for the button:
Private Sub executor_Click(sender As Object, e As EventArgs) Handles executor.Click
Dim thisDate As String, myFile As String, toPath As String, FSO As Object, fFormat As String
myFile = nameInput.ToString
thisDate = Format(Now(), "yyyymmdd")
toPath = "C:\Test\"
fFormat = "AQDOS" & myFile & thisDate & ".pdf"
FSO = CreateObject("scripting.filesystemobject")
FSO.CopyFile(Source:=sFileSelected, Destination:=toPath & fFormat)
So it highlights FSO.CopyFile(Source:=sFileSelected, Destination:=toPath & fFormat)
and says that the exception is unhandled. 'sFileSelected' is a public variable whose value is calculated in a different subroutine. I don't know if this is the core of the issue or no but for whatever reason, it does not like that last line.
Is my issue with trying to append strings onto the name?
EDIT: Ok so apparently the issue exists with the source, as now I have the code performing the formatting correctly. So my question then, is, how do I reference a variable that is defined elsewhere by a different button_Click
?
Upvotes: 0
Views: 28
Reputation: 288
Try rewriting your last line and pass in the pure parameters:
FSO.CopyFile(sFileSelected, toPath & fFormat)
But I prefer you passed in complete variavbles not concatenate them in the parameter functions for cleaner code:
dim string as fileDestination = toPath & fFormat
FSO.CopyFile(sFileSelected, fileDestination
Upvotes: 0