#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 25
Default Macro to open a file

I have a simple macro in a workbook named "daily info" that activates when i
click a button, the macro opens a workbook called "Phonebook" both of these
workbooks are contained in the same folder called "my reports". What i need
is a macro that will look inside the folder called "my reports" even if i
move this folder to another place on my computer. In effect only looking
inside the immediate folder. I hope this makes sense.
Thanks for any help
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 248
Default Macro to open a file

Use thisworkbook.Path to get the path of the workbook containing the macro
and use it to open the desired file.

-------------------------------------
Pl. click ''Yes'' if this was helpful...



"jackrobyn1" wrote:

I have a simple macro in a workbook named "daily info" that activates when i
click a button, the macro opens a workbook called "Phonebook" both of these
workbooks are contained in the same folder called "my reports". What i need
is a macro that will look inside the folder called "my reports" even if i
move this folder to another place on my computer. In effect only looking
inside the immediate folder. I hope this makes sense.
Thanks for any help

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 25
Default Macro to open a file

As I recorded the macro with the macro recorder im not sure what to do with
the information you have given me, can you explain or give an example
Thanks

"Sheeloo" wrote:

Use thisworkbook.Path to get the path of the workbook containing the macro
and use it to open the desired file.

-------------------------------------
Pl. click ''Yes'' if this was helpful...



"jackrobyn1" wrote:

I have a simple macro in a workbook named "daily info" that activates when i
click a button, the macro opens a workbook called "Phonebook" both of these
workbooks are contained in the same folder called "my reports". What i need
is a macro that will look inside the folder called "my reports" even if i
move this folder to another place on my computer. In effect only looking
inside the immediate folder. I hope this makes sense.
Thanks for any help

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Macro to open a file

Are you looking in that folder for the file named PhoneBook.xls?

Dim PBWkbk as workbook
Dim PBName as string

PBName = "phonebook.xls"

set pbwkbk = nothing
on error resume next
set pbwkbk = workbooks.open(filename:=thisworkbook.path & "\" & pbname
on error goto 0

if pbwkbk is nothing then
msgbox pbname & " wasn't found in " & thisworkbook.path
else
msgbox "It opened!
end if



jackrobyn1 wrote:

I have a simple macro in a workbook named "daily info" that activates when i
click a button, the macro opens a workbook called "Phonebook" both of these
workbooks are contained in the same folder called "my reports". What i need
is a macro that will look inside the folder called "my reports" even if i
move this folder to another place on my computer. In effect only looking
inside the immediate folder. I hope this makes sense.
Thanks for any help


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 25
Default Macro to open a file

Great thanks

"Dave Peterson" wrote:

Are you looking in that folder for the file named PhoneBook.xls?

Dim PBWkbk as workbook
Dim PBName as string

PBName = "phonebook.xls"

set pbwkbk = nothing
on error resume next
set pbwkbk = workbooks.open(filename:=thisworkbook.path & "\" & pbname
on error goto 0

if pbwkbk is nothing then
msgbox pbname & " wasn't found in " & thisworkbook.path
else
msgbox "It opened!
end if



jackrobyn1 wrote:

I have a simple macro in a workbook named "daily info" that activates when i
click a button, the macro opens a workbook called "Phonebook" both of these
workbooks are contained in the same folder called "my reports". What i need
is a macro that will look inside the folder called "my reports" even if i
move this folder to another place on my computer. In effect only looking
inside the immediate folder. I hope this makes sense.
Thanks for any help


--

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
Macro to run on file open Marie Bayes Excel Discussion (Misc queries) 17 November 5th 08 07:47 PM
Running macro on file open excelnerd Excel Discussion (Misc queries) 3 March 12th 08 10:51 PM
Macro to Open, then Close another File HROBERTSON Excel Discussion (Misc queries) 1 January 8th 07 06:41 PM
Open File within a macro Rob Excel Discussion (Misc queries) 10 June 29th 06 08:55 PM
I want to make a Macro that would so I can open a CSV file and it. Bob L Excel Discussion (Misc queries) 2 March 8th 05 01:04 AM


All times are GMT +1. The time now is 12:42 PM.

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

About Us

"It's about Microsoft Excel"