Results 1 to 3 of 3
  1. #1
    Star Lounger
    Join Date
    Nov 2005
    Location
    London, Gtr London, United Kingdom
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Variable in a file path (VBA/Powerpoint/2000)

    Hi everyone.

    A quick question. Is it possible to use a variable in a file path that occurs several times in some code. For example, c:Pictureschart.....?

    many thanks

    Thom

  2. Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: Variable in a file path (VBA/Powerpoint/2000)

    Yes, by declaring a constant or variable, and using & to concatenate strings. For example:

    Dim strFile As String
    Dim strPath As String
    strPath = "C:PicturesChart"
    strFile = "Orders.xls"
    Workbooks.Open strPath & strFile
    ...
    strFile = "Accounts.xls"
    Workbooks.Open strPath & strFile
    ...

    If the path will never change, you can replace

    Dim strPath As String
    strPath = "C:PicturesChart"

    with

    Const strPath = "C:PicturesChart"

  4. #3
    Star Lounger
    Join Date
    Nov 2005
    Location
    London, Gtr London, United Kingdom
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Variable in a file path (VBA/Powerpoint/2000)

    Many thanks for this Hans

Posting Permissions

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