Help saving file to network location VBA

ginner159

New Member
Joined
Jun 16, 2011
Messages
15
sorry if posted in wrong place ive serched around and tryied various options but to no avail.

i need to save a file accrossthe local network. i have set it up as a macro and works fine if saving on the same computer as the file was set up. i then copyied and changed the code to try make it save to a shared folder on another pc... failed... mapped the drive and tried it that way ... failed.

its my first time really using VB/VBA so please be kind :)

Code:
Sub Saveoffice()
     'Saves filename as Boat name plus customer and the date due in Dock
 
    Dim newFile As String, fName As String, fName1 As String, fName2 As String
     ' Don't use "/" in date, invalid syntax
    fName = Range("B3").Value
    fName1 = Range("B4").Value
    fName2 = Range("H9").Value
     'Change the date format to whatever you'd like, but make sure it's in quotes
    newFile = fName & " " & fName1 & " " & Format$(fName2, "dd-mm-yyyy")
     ' Change directory to suit your PC, including USER NAME
    ChDrive "Z:\"
    ChDir "Z:\test"
    ActiveWorkbook.SaveAs Filename:=newFile
 
End Sub
 
also the message comes up with a box saying where it is to be stored

Is it correct?
please look VERY CLOSELY...

according to the code provided by macro recorder it should look like this
Z:\test\Dock Work Sheet blank.xls
 
Upvote 0

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
the message looked like this

untitled1.bmp


in response to the merged cells Ive unmerged them and will try again when im back at work tommorrow.

thanks again for all your help guys
 
Upvote 0
well ive managed to do it found it on another website, but ive edited it a little to match my file directorys. its acived by changing the save as function directly there is just one little niggle im having now.

its saving the file and opening the save as box. what i want it do is open the folder i specified in the code but let me then selct the sub folder it needs to be saved in.

heres the code
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
'Saves filename as value of Boat name plus customer and the date due in Wide dock

Dim newFile As String, fName As String, fName1 As String, fName2 As String
' Don't use "/" in date, invalid syntax
fName = Range("B3").Value
fName1 = Range("B4").Value
fName2 = Range("B6").Value
'Change the date format to whatever you'd like, but make sure it's in quotes
newFile = fName & " " & fName1 & " " & Format$(fName2, "dd-mm-yyyy")

ActiveWorkbook.SaveAs Filename:="Z:\" & newFile
End Sub

the folder structure is as follows
Z:\
Z:\Dock Work\
Z:\Dock Work\Narrow Dock\
Z:\Dock Work\Wide Dock\

to clear up i want to be able to save as to either the wide or narrow after the save as opens
 
Upvote 0
Just wanted to say thanks to all involved in this thread. It helped me bunches with what I was trying to do here.

How did you resolve your final problem though ginner159?

Regards
John
 
Upvote 0
i just re recorded a normal save macro just saving a file to the networked drive then added the extra bits to make it achieve the file name desired
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,774
Members
452,942
Latest member
VijayNewtoExcel

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