Add Copy file string

juneau730

Board Regular
Joined
Jun 7, 2018
Messages
111
Good morning all,

I have the following code that works perfectly for what it is intended for, but I need to add a string in it, that copies a file from a network share, to an application path folder and can't seem to find a working way to do so. Hoping you can help out.

It would need to go in before the Set objShell = VBA.CreateObject("wscript.shell") line.

VBA Code:
Sub UpdateSeparatedUserInfo()
    Dim objShell As Object
    Dim strGLReport As String
    Dim blnContinue, strQuestion
    Dim objExcel
    
    strQuestion = "This action will restrict all database activity until completed. " _
        & "Do you wish to continue?"
    
    blnContinue = MsgBox(strQuestion, vbYesNo, "Update Separated User Info")
    
    If blnContinue = vbNo Then
        Forms![_Navigation Form].NavBtnSeparatedUsersMonitors.SetFocus
        Exit Sub
    End If
    
 Set objShell = VBA.CreateObject("wscript.shell")
    strGLReport = Application.CurrentProject.Path & "\G-L\Gains and Loss Report.xlsx"
    
 ' MyFunctions.SleepNow 3000
        
    Forms![_Navigation Form].NavigationSubform.Form.Requery
 
  DoCmd.SetWarnings False
    DoCmd.RunSQL "DELETE * FROM [tbl GainsandLoss]"
    DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, "tbl GainsandLoss", strGLReport, True
    DoCmd.SetWarnings True
    Forms![_Navigation Form].NavigationSubform.Form.Requery
    
End Sub
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
You'd just need a line that does that? This one provides no options such as determining if it exists or is open. You'd need to use FileScripting object for that.
Correct, I just need a line that will copy from the network share, to the application path folder. Though thinking about it, a function that replaces/overwrites the existing file in the application path folder would be good.

That is one I had tried using and was unsuccessful in getting it to work in the overall script.
 
Upvote 0
There are tons of examples you can find for that. If you create a function for this and call it from your existing code, you might be able to use said function in other cases, making it more versatile. If you get stuck, post your code attempts?
 
Upvote 0
I would use DIR() to see if it exists.?

Code:
Sub CopyTheFile()
Dim strSource As String, strTarget As String
Dim blnFileExists As Boolean

strSource = "c:\temp\invoice.pdf"
strTarget = "c:\temp\Test.pdf"

blnFileExists = Dir(strSource) <> ""
If blnFileExists Then
    FileCopy strSource, strTarget
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,880
Messages
6,175,153
Members
452,615
Latest member
bogeys2birdies

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