Thank you for Visiting my Blog

Thursday, 12 October 2017

How to open any file using marcos



To open any file which is placed at any location in system please use below code:


Below example both file is placed at the same location . so I am directly reading directory name but if you want to get from other location you can modify the code.


Sub fileopen()
Dim fname As String, wbTarget As Workbook
''''''/**********provide the filename which need to open ***********/''''''''''

fname = InputBox(Prompt:="Name of the file:", _
    Title:="Please Enter file name", Default:="myfile.xlsx")

''''''/**********filelocation can be get by User ***********/''''''''''


Filename = ActiveWorkbook.Path & "\" & fname

''''''/*********below is the function to open the file ***********/''''''''''

Set wbTarget = Workbooks.Open(Filename)

End Sub

 Input#



 Output#
 
 
 
 
 
 

No comments:

Post a Comment