Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Open specific workbook

Dear Sirs,

I want to program an addin to my excel to open a workbook named
"Prod_01.xlsx". and I will share this addin with my colleagues,they have same
file in their computer,but kept in different path. so I thin my macro should
always find the workbooks("Prod_01.xlsx") firstly, then open it.Anybody can
provide these code?

thanks advancely.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Open specific workbook

Li,

I would use code in the workbook open event that asks for the path to that file the first time that
the add-in is opened, along the lines of

Public MyFName As String

Private Sub Workbook_Open()

If Sheets(1).Range("A1").Value = "" Then
MsgBox "Please browse to and select your Prod_01.xlsx file in the next dialog box"
Sheets(1).Range("A1").Value = Application.GetOpenFilename
End If
MyFName = Sheets(1).Range("A1").Value
End Sub

Then anytime your add-in needs that file, use

Workbooks.Open MyFName


HTH,
Bernie
MS Excel MVP


"Li Jianyong" wrote in message
...
Dear Sirs,

I want to program an addin to my excel to open a workbook named
"Prod_01.xlsx". and I will share this addin with my colleagues,they have same
file in their computer,but kept in different path. so I thin my macro should
always find the workbooks("Prod_01.xlsx") firstly, then open it.Anybody can
provide these code?

thanks advancely.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Open specific workbook

Dear Bernie,

thanks for your code. But if the user changed the path of the workbook
"prod_01.xlsx", what will happen?

Best regards
Li Jianyong

"Bernie Deitrick" wrote:

Li,

I would use code in the workbook open event that asks for the path to that file the first time that
the add-in is opened, along the lines of

Public MyFName As String

Private Sub Workbook_Open()

If Sheets(1).Range("A1").Value = "" Then
MsgBox "Please browse to and select your Prod_01.xlsx file in the next dialog box"
Sheets(1).Range("A1").Value = Application.GetOpenFilename
End If
MyFName = Sheets(1).Range("A1").Value
End Sub

Then anytime your add-in needs that file, use

Workbooks.Open MyFName


HTH,
Bernie
MS Excel MVP


"Li Jianyong" wrote in message
...
Dear Sirs,

I want to program an addin to my excel to open a workbook named
"Prod_01.xlsx". and I will share this addin with my colleagues,they have same
file in their computer,but kept in different path. so I thin my macro should
always find the workbooks("Prod_01.xlsx") firstly, then open it.Anybody can
provide these code?

thanks advancely.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Open specific workbook

Li,

Then the file won't open, but you could capture the error from the Workbooks.Open line to request
that the user select the file in its new folder, and over-write the path and filename data in cell
A1.

HTH,
Bernie
MS Excel MVP


"Li Jianyong" wrote in message
...
Dear Bernie,

thanks for your code. But if the user changed the path of the workbook
"prod_01.xlsx", what will happen?

Best regards
Li Jianyong

"Bernie Deitrick" wrote:

Li,

I would use code in the workbook open event that asks for the path to that file the first time
that
the add-in is opened, along the lines of

Public MyFName As String

Private Sub Workbook_Open()

If Sheets(1).Range("A1").Value = "" Then
MsgBox "Please browse to and select your Prod_01.xlsx file in the next dialog box"
Sheets(1).Range("A1").Value = Application.GetOpenFilename
End If
MyFName = Sheets(1).Range("A1").Value
End Sub

Then anytime your add-in needs that file, use

Workbooks.Open MyFName


HTH,
Bernie
MS Excel MVP


"Li Jianyong" wrote in message
...
Dear Sirs,

I want to program an addin to my excel to open a workbook named
"Prod_01.xlsx". and I will share this addin with my colleagues,they have same
file in their computer,but kept in different path. so I thin my macro should
always find the workbooks("Prod_01.xlsx") firstly, then open it.Anybody can
provide these code?

thanks advancely.






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
open workbook to specific sheet Mr E[_2_] Excel Worksheet Functions 1 April 9th 10 06:53 PM
Open workbook to specific worksheet mathel Excel Programming 4 February 1st 10 06:46 PM
Open a new workbook with a specific name Jepane Excel Discussion (Misc queries) 3 June 21st 07 04:09 PM
Open a specific workbook...find value from other open workbook and then insert cells values in cell next to it. [email protected] Excel Programming 1 May 13th 07 01:46 PM
Open Specific Sheet in Workbook jhahes[_9_] Excel Programming 1 June 24th 05 09:26 PM


All times are GMT +1. The time now is 08:23 AM.

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"