Workbooks.Open Filename error

Kurt

Well-known Member
Joined
Jul 23, 2002
Messages
1,664
I am getting the error Compile error: Syntax error on this line of code:

Set wbSource = Workbooks.Open Filename

the wbSource variable is declared.

What else might be going on?

Code:
Sub GetOpenFName()

    Dim FileName As Variant

    Dim Filt As String, Title As String

    Dim FilterIndex As Integer, Response As Integer

    Dim wbSource As Workbook

    Dim wbDest As Workbook


    Set wbDest = ActiveWorkbook
    

    '   Set to Specified Path\Folder

        On Error Resume Next

        ChDir ActiveWorkbook.Path

    '   Set File Filter

        'Filt = "Excel Files (*.xls, *.xlsx, *.xlsm, *.xlsb), *.xls, *.xlsx, *.xlsm, *.xlsb"

    '   Set *.* to Default

        'FilterIndex = 5

    '   Set Dialogue Box Caption

        Title = "Please select a different File"

    '   Get FileName

        FileName = Application.GetOpenFilename(FileFilter:=Filt, FilterIndex:=FilterIndex, Title:=Title)

    '   Exit if Dialogue box cancelled

        If FileName = False Then

            Response = MsgBox("No File was selected", vbOKOnly & vbCritical, "Selection Error")

            Exit Sub

        End If

    '   Display Full Path & File Name

        Response = MsgBox("You selected " & FileName, vbInformation, "Proceed")

    '   Open Selected Workbook

        Set wbSource = Workbooks.Open FileName
    
 

    'Copy from source workbook to dest workbook

       wbSource.Sheets("RawData").Range("A1:S29089").Copy wbDest.Sheets(“DataCalcs”).Range(“A1”)

 

End Sub
 
Last edited by a moderator:
Hello Yongle and Fluff,

Yongle that was it! I found out the UNC path.

I should have remember this from a long time ago but thank you for pointing that out.

Fluff, please don't beat me up. I just see a reply with Quotes that is why this is happening otherwise I would be glad to save the space.

Now for the second part of the question.

Does anyone have some easy workable code to copy a worksheet from a closed workbook to an open workbook?

Many thanks for all of your efforts Yongle and Fluff!!
 
Last edited by a moderator:
Upvote 0

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
The Reply button is just to the left of the Reply With Quotes button. ;)

If you want to copy from a closed workbook, without opening it, then you will need to start a new thread as that is completely different code.
If you are happy for the workbook to be opened, what sheet to do you want to copy?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top