Open outside excel file type mismatch error

drop05

Active Member
Joined
Mar 23, 2021
Messages
285
Office Version
  1. 365
Platform
  1. Windows
Hi i am getting a type mismatch error when trying to open the workbook at the set wbk line, not sure why i am getting this error
VBA Code:
Dim FNames As Variant
Dim Cnt As Long
Dim Wbk As Workbook
Dim MstWbk As Workbook
Dim Ws As Worksheet

Set MstWbk = ThisWorkbook
   
FNames = Application.GetOpenFilename(FileFilter:="Excel files (*.xls*), *.xls*", MultiSelect:=True)
If Not IsArray(FNames) Then Exit Sub
Set Wbk = Workbooks.Open(FNames)
Wbk.Worksheets("Payment").Range("M6:BW6").Copy
Wbk.Close False
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
If you're only going to open one file, then use this:

VBA Code:
Sub testopen()
  Dim FNames As Variant
  Dim Cnt As Long
  Dim Wbk As Workbook
  Dim MstWbk As Workbook
  Dim Ws As Worksheet
  
  Set MstWbk = ThisWorkbook
     
  FNames = Application.GetOpenFilename(FileFilter:="Excel files (*.xls*), *.xls*", MultiSelect:=False)
  If FNames = False Then Exit Sub
  Set Wbk = Workbooks.Open(FNames)
  Wbk.Worksheets("Payment").Range("M6:BW6").Copy
  Wbk.Close False
  '
  '
End Sub
 
Upvote 0
If you're only going to open one file, then use this:

VBA Code:
Sub testopen()
  Dim FNames As Variant
  Dim Cnt As Long
  Dim Wbk As Workbook
  Dim MstWbk As Workbook
  Dim Ws As Worksheet
 
  Set MstWbk = ThisWorkbook
    
  FNames = Application.GetOpenFilename(FileFilter:="Excel files (*.xls*), *.xls*", MultiSelect:=False)
  If FNames = False Then Exit Sub
  Set Wbk = Workbooks.Open(FNames)
  Wbk.Worksheets("Payment").Range("M6:BW6").Copy
  Wbk.Close False
  '
  '
End Sub
If you're only going to open one file, then use this:

VBA Code:
Sub testopen()
  Dim FNames As Variant
  Dim Cnt As Long
  Dim Wbk As Workbook
  Dim MstWbk As Workbook
  Dim Ws As Worksheet
 
  Set MstWbk = ThisWorkbook
    
  FNames = Application.GetOpenFilename(FileFilter:="Excel files (*.xls*), *.xls*", MultiSelect:=False)
  If FNames = False Then Exit Sub
  Set Wbk = Workbooks.Open(FNames)
  Wbk.Worksheets("Payment").Range("M6:BW6").Copy
  Wbk.Close False
  '
  '
End Sub
Hi thank you for this i am getting an error at the set WBk
 
Upvote 0
What does the error message say?

Could you describe exactly step by step what you do?
 
Upvote 0
Solution
What does the error message say?

Could you describe exactly step by step what you do?
sorry disregard last comment i closed and opened it again and ran it and it was good not sure why that happened but looks like it is good now
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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