2 May 2012

How to open another excel file from macro | How to open another excel file in vba | open an excel file in vba


                  Hi Friends, in this article i will explain about How to open another excel file using Macro in Excel 2007.

                              A macro is a set of operations for a spreadsheet. Suppose if you want to open new excel file, the file name is in A1 ,for that we can write the code in Macro and Run the macro then the file will open.


In previous article i explained How to create a Macro.

We can open the another excel file in 2 ways.
1.select the file what do we want
2.open excel file automatically

1.Open excel file automatically Example:

The below example is shows the file selected by us.
Copy and paste the below code in the Microsoft Visual Basic code  and Goto Excel and click on the Macros and Run.
When we Run this then an open dialog box will display.Select the excel file what do you want then that file will open.

  Sub project()
           Sheets("Sheet1").Select
           Range("A1").Value = "beam design_fps"
           If Range("A1").Value = "beam design_fps" Then
           MsgBox "The template is updated.Take new one"
Workbooks.Open ("C:\Users\S17user\Documents\" + Range("A1").Value + "")
End If
      End Sub
          
 
2. Using select the file what do we want.

Example:
Copy and paste the below code in the Microsoft Visual Basic code  and Goto Excel and click on the Macros and Run.

When we run this code then Roja.xls will open automatically

Sub project()
           Sheets("Sheet1").Select
           Range("A1").Value = "Roja"
           If Range("A1").Value = "Roja" Then
           MsgBox "The template is updated.Take new one"
            Workbooks.Open ("C:\Users\S17user\Documents\" + Range("A1").Value + "")
End If
      End Sub



No comments:

Post a Comment