Consulting

Results 1 to 5 of 5

Thread: Open a Workbook with path

  1. #1

    Open a Workbook with path

    Hello,


    I want to open a workbook with path which is stated in the Range B1 of the Active Workbook. My code gives me the Runtime error 1004 and says that the Workbook cannot be found although the name is correct.

    Here is my code:

    Sub OpenReport()
    Dim path As String
    path = ActiveWorkbook.Worksheets("Sheet1").Range("B1").Value
    Dim name As String
    name = ActiveWorkbook.Worksheets("Sheet1").Range("B2").Value
    Workbooks.Open Filename := path & name
    End Sub


    in B1 there is the path : C:\Users\BenutzerXY\Desktop\
    in B2: Map1.xls

  2. #2
    Does it work if you change B1 to "C:\Documents and Settings\Owner\Desktop\"?
    The "BenutzerXY" is the German person that owns the machine I assume?


    This should work also. You don't have to put the path to the desktop in. This code will do that.
    It only works of course if the file is on the desktop.


    Sub OpenReport()
        Dim path As String
        Dim name As String
        Application.ScreenUpdating = False
        Range("B1").Value = CreateObject("WScript.Shell").specialfolders("Desktop") & "\"
        path = ActiveWorkbook.Worksheets("Sheet1").Range("B1").Value
        name = ActiveWorkbook.Worksheets("Sheet1").Range("B2").Value
        Workbooks.Open Filename:=path & name
        Application.ScreenUpdating = True
    End Sub
    Last edited by jolivanes; 12-06-2015 at 10:31 AM. Reason: Add code

  3. #3
    Hi jolivanes,

    thank you for your help. What can I do if my file is not on the desktop?
    "The "BenutzerXY" is the German person that owns the machine I assume"?" --> yes




  4. #4
    Re: "What can I do if my file is not on the desktop?"
    All you can do there is making sure that the path is right and that the backslash is added. Copy it from the Explorer address bar maybe.
    Or search for the file with
    Application.GetOpenFilename()
    You also have to leave the following line out
    Range("B1").Value = CreateObject("WScript.Shell").specialfolders("Desktop") & "\"

  5. #5
    Thank you

Posting Permissions

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