Closed Thread
Results 1 to 5 of 5

Write Procedure With Logic Test To Open File From Given Directory

  1. #1
    Carl Bowman
    Guest

    Write Procedure With Logic Test To Open File From Given Directory

    I need to write a procedure (not sure if this is what you call it) to cause
    the file "data.xls" to be opened from path "C:\data\FEB" if the month is
    February (evidenced by the text "FEB" in cell L45 in worksheet "Process") and
    a file with the same name to be opened from path "C:\data\MAR" if the month
    is March (evidenced by the text "MAR" in cell L45 of worksheet "Process").
    This may be simple for some but I don't even know where to start. Thanks!

  2. #2
    Markus Scheible
    Guest

    Write Procedure With Logic Test To Open File From Given Directory

    Hi Carl,

    >the file "data.xls" to be opened from path "C:\data\FEB"

    if the month is
    >February (evidenced by the text "FEB" in cell L45 in

    worksheet "Process") and


    Try:

    workbooks.Open FileName:="C:\data\" & Sheets
    ("Process").Range("L45").Value & "\data.xls"

    Best

    Markus

  3. #3
    David Fam?
    Guest

    Re: Write Procedure With Logic Test To Open File From Given Directory

    OK,
    if I've undestood, you want to open files with the same names and
    different paths variable on a cell value. If this is correct, do as
    follows:

    Create a command button (from the Control Toolbox) and (in the Design
    Mode - always selectable in the Control Tollbox Taskbar) double click
    it. A macro screen will popup with a couple of lines written:

    >> Private Sub CommandButton1_Click()
    >> ' Here write the following code
    >> End Sub


    The following code will create from cell L45 the right path and will
    open the file (without ">>"):

    >> ' Starts Here
    >>
    >> dim sPath as string
    >> dim sPartialPath as string
    >> dim sFileName as string
    >>
    >> sFileName = "data.xls"
    >> sPartialPath = worksheets("Process").cells(45,12).value
    >> sPath = "C:\data\" & sPartialPath & "\" & sFileName
    >>
    >> Workbooks.open(sPath)
    >> ' Finishes Here


    Now, saving and then pushing the button (NOT in Design Mode) the
    desired file should be opened.

    Hope it Helps,
    David

  4. #4
    Carl Bowman
    Guest

    RE: Write Procedure With Logic Test To Open File From Given Directory

    Thanks a million Markus! This worked great and has opened up a whole new
    world to me!

    "Markus Scheible" wrote:

    > Hi Carl,
    >
    > >the file "data.xls" to be opened from path "C:\data\FEB"

    > if the month is
    > >February (evidenced by the text "FEB" in cell L45 in

    > worksheet "Process") and
    >
    >
    > Try:
    >
    > workbooks.Open FileName:="C:\data\" & Sheets
    > ("Process").Range("L45").Value & "\data.xls"
    >
    > Best
    >
    > Markus
    >


  5. #5
    Carl Bowman
    Guest

    Re: Write Procedure With Logic Test To Open File From Given Direct

    Thanks, David. I will need to study this more. I was able to use the other
    suggestion and it worked just fine. I still see some use for what you are
    saying.

    "David Fam?" wrote:

    > OK,
    > if I've undestood, you want to open files with the same names and
    > different paths variable on a cell value. If this is correct, do as
    > follows:
    >
    > Create a command button (from the Control Toolbox) and (in the Design
    > Mode - always selectable in the Control Tollbox Taskbar) double click
    > it. A macro screen will popup with a couple of lines written:
    >
    > >> Private Sub CommandButton1_Click()
    > >> ' Here write the following code
    > >> End Sub

    >
    > The following code will create from cell L45 the right path and will
    > open the file (without ">>"):
    >
    > >> ' Starts Here
    > >>
    > >> dim sPath as string
    > >> dim sPartialPath as string
    > >> dim sFileName as string
    > >>
    > >> sFileName = "data.xls"
    > >> sPartialPath = worksheets("Process").cells(45,12).value
    > >> sPath = "C:\data\" & sPartialPath & "\" & sFileName
    > >>
    > >> Workbooks.open(sPath)
    > >> ' Finishes Here

    >
    > Now, saving and then pushing the button (NOT in Design Mode) the
    > desired file should be opened.
    >
    > Hope it Helps,
    > David
    >


Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1