Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9
Default 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?
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default 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
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,942
Default 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?

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
File opens with Enable or Disable Macro animalfriend7 Excel Discussion (Misc queries) 1 November 8th 06 04:29 PM
File automatically opens Brad Excel Discussion (Misc queries) 1 January 6th 06 05:00 PM
Excel file automatically opens - More Info Lost4Now Excel Discussion (Misc queries) 2 December 4th 05 11:01 PM
Excel file automatically opens Lost4Now Excel Discussion (Misc queries) 6 December 4th 05 09:35 PM
Automatically update from source when file opens P Flater Excel Discussion (Misc queries) 1 March 25th 05 09:41 PM


All times are GMT +1. The time now is 09:43 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"