ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   writing a macro that automatically opens another file (https://www.excelbanter.com/excel-discussion-misc-queries/198363-writing-macro-automatically-opens-another-file.html)

J.Mart[_2_]

writing a macro that automatically opens another file
 
Hi,
How do I start to write a macro in excel that automatically opens the file
"BEA U.S Flows & Stock 1980-2007" when the file "Duignan_US-ASIA_EU Trade &
FDI Flows" is opened?

Dave Peterson

writing a macro that automatically opens another file
 
You could add a macro to the first workbook so that when it's opened, the second
workbook is opened:

Option Explicit
Sub Auto_Open()
dim myPath as string
dim myFileName as string
dim wkbk as workbook

myPath = "C:\yourpathtothefile\" '<-- include the trailing backslash!
myfilename = "BEA U.S Flows & Stock 1980-2007.xls"

set wkbk = nothing
on error resume next
set wkbk = workbooks(myfilename)
on error goto 0

if wkbk is nothing then
'open it!
set wkbk = workbooks.open(filename:=mypath & myfilename)
else
'do nothing, it's already open
end if

End sub


If you're new to macros:

Debra Dalgleish has some notes how to implement macros he
http://www.contextures.com/xlvba01.html

David McRitchie has an intro to macros:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Ron de Bruin's intro to macros:
http://www.rondebruin.nl/code.htm

(General, Regular and Standard modules all describe the same thing.)

J.Mart wrote:

Hi,
How do I start to write a macro in excel that automatically opens the file
"BEA U.S Flows & Stock 1980-2007" when the file "Duignan_US-ASIA_EU Trade &
FDI Flows" is opened?


--

Dave Peterson

FSt1

writing a macro that automatically opens another file
 
hi
use the workbook open event on the last file.
Private Sub Workbook_Open()
Workbooks.Open Filename:= _
"C:\Your\file\path\BEA U.S Flows & Stock 1980-2007.xls"
'if you want the first wb to be active then add this line
'windows("Duignan_US-ASIA_EU Trade & FDI Flows").activate
End Sub

regards
FSt1

"J.Mart" wrote:

Hi,
How do I start to write a macro in excel that automatically opens the file
"BEA U.S Flows & Stock 1980-2007" when the file "Duignan_US-ASIA_EU Trade &
FDI Flows" is opened?


J.Mart[_2_]

writing a macro that automatically opens another file
 
Great. Thanks for the additional resources.

"Dave Peterson" wrote:

You could add a macro to the first workbook so that when it's opened, the second
workbook is opened:

Option Explicit
Sub Auto_Open()
dim myPath as string
dim myFileName as string
dim wkbk as workbook

myPath = "C:\yourpathtothefile\" '<-- include the trailing backslash!
myfilename = "BEA U.S Flows & Stock 1980-2007.xls"

set wkbk = nothing
on error resume next
set wkbk = workbooks(myfilename)
on error goto 0

if wkbk is nothing then
'open it!
set wkbk = workbooks.open(filename:=mypath & myfilename)
else
'do nothing, it's already open
end if

End sub


If you're new to macros:

Debra Dalgleish has some notes how to implement macros he
http://www.contextures.com/xlvba01.html

David McRitchie has an intro to macros:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Ron de Bruin's intro to macros:
http://www.rondebruin.nl/code.htm

(General, Regular and Standard modules all describe the same thing.)

J.Mart wrote:

Hi,
How do I start to write a macro in excel that automatically opens the file
"BEA U.S Flows & Stock 1980-2007" when the file "Duignan_US-ASIA_EU Trade &
FDI Flows" is opened?


--

Dave Peterson



All times are GMT +1. The time now is 02:20 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com