Consulting

Results 1 to 5 of 5

Thread: VBA Code to Save into a Network Drive

  1. #1

    VBA Code to Save into a Network Drive

    Hi!

    Part of my code is not working. The part that is not working is saving the file into an specific file in a network drive.

    Here is the VBA that I'm using.
    ChDir "G:\NARS Planning\Open Order Reports"
    ActiveWorkbook.SaveAs Filename:="NARS Open Order Report " & Format(Date, "mm.dd.yy") & ".xlsx", FileFormat:=xlOpenXMLWorkbook
    Any input will be greatly appreciated.

    Thank you.
    Last edited by SamT; 06-23-2017 at 06:50 AM.

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    : Try
    Dim ThePath As String
    
    ThePath = "G:\NARS Planning\Open Order Reports"
    ActiveWorkbook.SaveAs Filename:=ThePath & "NARS Open Order Report " &  Format(Date, "mm.dd.yy") & ".xlsx", FileFormat:=xlOpenXMLWorkbook
    BTW, I usually save my files with a date stamp format of Year Month Day, so they list in Date order.

    Yours will be listed like
    Jan 1 1950
    Jan 1 1951
    Jan 1 1952
    etc
    Jan 2 1950
    Jan 2 1951
    Etc, etc, etc
    Feb 1 1950
    Feb 1 1951
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You are missing a path separator

    Dim ThePath As String 
     
    ThePath = "G:\NARS Planning\Open Order Reports" 
    ActiveWorkbook.SaveAs Filename:=ThePath & Application.PathSeparator & "NARS Open Order Report " &  Format(Date, "mm.dd.yy") & ".xlsx", FileFormat:=xlOpenXMLWorkbook
    or

    Dim ThePath As String 
     
    ThePath = "G:\NARS Planning\Open Order Reports" & Application.PathSeparator
    ActiveWorkbook.SaveAs Filename:=ThePath & "NARS Open Order Report " &  Format(Date, "mm.dd.yy") & ".xlsx", FileFormat:=xlOpenXMLWorkbook
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Stupid keyboard.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  5. #5
    Thank you both for your efforts. AT XLD; AT SAMT

    It worked!!

    Edward.

    Quote Originally Posted by xld View Post
    You are missing a path separator

    Dim ThePath As String 
     
    ThePath = "G:\NARS Planning\Open Order Reports" 
    ActiveWorkbook.SaveAs Filename:=ThePath & Application.PathSeparator & "NARS Open Order Report " &  Format(Date, "mm.dd.yy") & ".xlsx", FileFormat:=xlOpenXMLWorkbook
    or

    Dim ThePath As String 
     
    ThePath = "G:\NARS Planning\Open Order Reports" & Application.PathSeparator
    ActiveWorkbook.SaveAs Filename:=ThePath & "NARS Open Order Report " &  Format(Date, "mm.dd.yy") & ".xlsx", FileFormat:=xlOpenXMLWorkbook

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •