Consulting

Results 1 to 8 of 8

Thread: Save As path help

  1. #1
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location

    Save As path help

    Hi Everyone,

    Can someone help me in making the following code direct the file to save in the following directory?

    V:\B&E Ops Support\Billing And Enrollment\B&E National Unit\National & ASO Profile and COBRA Sheets

    Public Sub CommandButton1_Click()
    If OptionButton1 = True Then
    ThisWorkbook.SaveAs Range("B5").Value & ".xls"
    Unload Me
    End If
    If OptionButton2 = True Then
    ThisWorkbook.SaveAs Range("B5").Value & ".xls"
    Sheets.PrintOut
    Unload Me
    End If
    End Sub
    Thanks in advance for your help

  2. #2
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Try this:

    Public Sub CommandButton1_Click()
      dim FilePath as string
      FilePath = "V:\B&E Ops Support\Billing And Enrollment\B&E National Unit\National & ASO Profile and COBRA Sheets\"
    If OptionButton1 = True Then
    ThisWorkbook.SaveAs FilePath & Range("B5").Value & ".xls"
    Unload Me
    End If
    If OptionButton2 = True Then
    ThisWorkbook.SaveAs FilePath & Range("B5").Value & ".xls"
    Sheets.PrintOut
    Unload Me
    End If
    End Sub


    I haven't tested it, but I think that should work...

    HTH,
    Last edited by Ken Puls; 12-14-2004 at 11:48 AM. Reason: Added the final slash in the file path
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  3. #3
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Hi Austen,
    'Omitted.  Same as Ken's
    Although, if you are going to call this location from many different locations in one file (e.g. multiple Sub Routines, UserForms, etc.) you may want to think about declaring it as a Public Const and keeping it Global. This will save you the trouble of calling/Dim'ming it multiple times when once is sufficient.

  4. #4
    VBAX Regular NateO's Avatar
    Joined
    Jun 2004
    Location
    Minneapolis, MN
    Posts
    90
    Location
    Or a private constant (versus variable). E.g.,

    Const FilePath  As String = "V:\B&E Ops Support\Billing And Enrollment\B&E National Unit\National & ASO Profile and COBRA Sheets\"
    Regards,
    Nate Oliver

  5. #5
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Nate, can you confirm for me...

    I know that the "Const FilePath As String..." would be declared at the top of the module (just under Option Explicit), but before the first (public/private) Sub, but...

    It would only work if the FilePath variable was called from a macro within that code module, correct? And declaring it public would allow it to be called from other modules within the same project?

    Thanks,
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  6. #6
    VBAX Regular NateO's Avatar
    Joined
    Jun 2004
    Location
    Minneapolis, MN
    Posts
    90
    Location
    Hello Ken,

    The scope will change pending your declaration.

    Procedural scope:

    Sub tester()
    Const FilePath As String = "V:\B&E Ops Support\Billing And Enrollment\B&E National Unit\National & ASO Profile and COBRA Sheets\"
    MsgBox FilePath
    End Sub
    Modular Scope:

    Private Const FilePath As String = "V:\B&E Ops Support\Billing And Enrollment\B&E National Unit\National & ASO Profile and COBRA Sheets\"
     
    Sub tester()
    MsgBox FilePath
    End Sub
    Project-wide scope:

    Public Const FilePath As String = "V:\B&E Ops Support\Billing And Enrollment\B&E National Unit\National & ASO Profile and COBRA Sheets\"
     
    Sub tester()
    MsgBox FilePath
    End Sub
    Hope this helps.
    Regards,
    Nate Oliver

  7. #7
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Perfect! Thanks!
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  8. #8
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    Thanks everyone. Works great, as usual. This board really gives great advice. You can consider this SOLVED!!

Posting Permissions

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