How to open another workbook in same folder?

tgregoire

New Member
Joined
Oct 3, 2021
Messages
7
Office Version
  1. 2013
Platform
  1. Windows
hi,
i am trying to open a file in the same folder. i have tried the below code and it is not working for me.
i get runtime error 1004
method 'open' of object 'workbook' failed

i have tried several other things and none seem to work. i can get it to open but that is only if i hardcode the file path. the issue with that is the user can move the workbook and file that needs opening around so it needs to be dynamic.

also could use some help closing it once i extract the data i need.



Workbooks.Open Filename:=ThisWorkbook.Path & "\openthis.xls"

i need to complete this project soon.
please help!
THANK YOU!! :)
 
ok

so to rule out the file

create a couple of dummy files to test this code on your desktop.

if the code works, then you know its your file.
 
Upvote 0

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
so it appears that after i export the file from our ERP system i have to export as an excel application file instead of as a document file and then manually saving it. kinda weird.


now i am having issues saving the macro enabled workbook using vba after importing the data from the other file. again i need to save it in the current directory.


Sub save_as()


Dim dt As String, wbname As String

wbname = " Statement of Income By Period (EPlant Different Fiscal Year) "
dt = Format(CStr(Now), "yyyy_mm_dd___hh:mm")
ActiveWorkbook.SaveAs Filename:=wbname & dt



End Sub

1633301242003.png
 
Upvote 0
never mind. i just realized i used : in the time stamp and thats not allowed.

thank you for your help.
 
Upvote 0
Hey.

Ok great. Glad you got it all working?
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,427
Members
448,961
Latest member
nzskater

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