VBA - Issues opening workbook with .xls extension but was saved from html

tonicohe

New Member
Joined
Dec 1, 2015
Messages
2
Hello,
I have a macro built to open a "source" workbook, copy and paste a range into a "master" workbook.
The "source" file has the .xls extension, but when you open it you get the warning that its in a different format.

Below is my code - its works fine if I have recently opened the "source" file - but when I exit excel and try to rerun the macro - I get a run time error saying it couldn't find a file with that name. Any thoughts on how I can fix my code to identify the file with .xls extension but that is in different format?

"Sub PropertiesTB()Application.DisplayAlerts = False


Dim PropTB As Workbook
Set PropTB = ThisWorkbook


Dim TBMonth
TBMonth = InputBox("Type Month and Year", "Month and Year", "MM/YY")
Dim MonthFolder
MonthFolder = InputBox("Current Month Folder", "Month")
Const FilePath = "Z:\2016 Financial Statements\"


Dim Source As String
Source = Dir(FilePath & MonthFolder & "\MMC\Property Financials\" & TBMonth & " Trial Balance.xls")
Do While Source <> vbNullString
Workbooks.Open FileName:=Source
Exit Do
Loop
Range("F7").Select
Range(Selection, Selection.End(xlToLeft)).Select
Range(Selection, Selection.End(xlDown)).Copy
PropTB.Activate
Sheets("Landmark TB").Select
Range("A7").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Windows("1015 Trial Balance.xls").Activate
ActiveWindow.Close savechanges:=False


Application.DisplayAlerts = True
End Sub"
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Hi Forum wizards: I still need help with the item above. I have tried a couple of different ways, but no matter what code I use, I can't get it to work due to the fact that the file format is different than the extension. Again, once I have opened it once in a current excel session - the code works fine.
Is there a code that would open any file with the name provided regardless of the extension? I have tried just leaving the file name with no extension, but I still get a run-time error saying "file name.xls" couldn't be found.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,875
Members
452,363
Latest member
merico17

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