VBa Code Did't Open Workbook

Closed
azmiismail Posts 17 Registration date Thursday March 3, 2011 Status Member Last seen July 20, 2011 - Jul 20, 2011 at 02:06 AM
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 - Jul 22, 2011 at 05:33 PM
Hello,

I'm having a major headache in figuring out why the VBA code which I'm applying at my office computer seems to work perfectly but fail to work at my home computer.

The code is simple,

Sub OpenT1()
Workbooks.Open ("C:\Users\azmi\Documents\n.xls")
End Sub

n.xls is my file name
I keep getting error 1004 message , file could not be found.
I'd checked,double checked and triple checked the file locations,spelling and so on but could not find any error.

Can somebody help me out

Thanks

1 response

smd_excel Posts 27 Registration date Saturday April 18, 2009 Status Member Last seen November 22, 2012
Jul 20, 2011 at 02:29 AM
Capture the file name and location i.e. in variable

file_path = Sheets("sheet1").Cells(1, 2)
file_name = Sheets("sheet1").Cells(2, 2)

Workbooks.Open Filename:=file_path & file_name
0
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
Jul 22, 2011 at 05:33 PM
What is difference if I hard code the path or get it via variable ?
0