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

Im trying to open a workbook using a macro. I keep getting an error that the file cant be found
I have two files in the same directory
Questions.xl
Admin.xl
The user opens questions.xls. When they have completed entering data, the macro in questions.xls saves the file and copies one row into admin.xls. I cant specify the path because this application is designed to be saved by different people in different places so I dont know what the path will be. I thought by putting both files in the same directory, the macro would know where to find admin.xls. Heres my code

Sub Complete(

' Save the users results, copies the summary information to the admi
'tool, saves the admin tool and closes it. Then it shows the user thei
'result

ThisWorkbook.sav
Sheets("Name ").Selec
Rows("3:3").Selec
Selection.Cop
Workbooks.Open Filename:="admin.xls
Rows("1000:1000").Selec
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=
False, Transpose:=Fals
Cells.Selec
Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlYes,
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBotto
ActiveWorkbook.sav
ActiveWindow.Clos

The error message says admin.xls can not be found. Any suggestions

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default opening a workbook

"doug h" wrote in message
...
I'm trying to open a workbook using a macro. I keep getting an error

that the file can't be found.
I have two files in the same directory:
Questions.xls
Admin.xls
The user opens questions.xls. When they have completed entering

data, the macro in questions.xls saves the file and copies one row
into admin.xls. I can't specify the path because this application is
designed to be saved by different people in different places so I don'
t know what the path will be. I thought by putting both files in the
same directory, the macro would know where to find admin.xls. Here's
my code:

Sub Complete()
'
' Save the users results, copies the summary information to the

admin
'tool, saves the admin tool and closes it. Then it shows the user

their
'results
'
ThisWorkbook.save
Sheets("Name ").Select
Rows("3:3").Select
Selection.Copy
Workbooks.Open Filename:="admin.xls"
Rows("1000:1000").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,

SkipBlanks:= _
False, Transpose:=False
Cells.Select
Selection.Sort Key1:=Range("A2"), Order1:=xlAscending,

Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
ActiveWorkbook.save
ActiveWindow.Close

The error message says admin.xls can not be found. Any suggestions?




Doug,

You could try using ThisWorkbook.Path to get the path of Questions.xls
and then tack it onto the "\admin.xls":

Workbooks.Open Filename:=ThisWorkbook.Path & "\admin.xls"


Hope this helps,

Mike


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,089
Default opening a workbook

Doug

Use: ThisWorkbook.Path to get the path of the first workbook
(Questions.xls)

Then use that to build the complete file name for the file you want to open

Workbooks.Open Filename:=ThisWorkbook.Path & "\admin.xls"

This obviously won't work if the files are not in the same folder

Regards

Trevor


"doug h" wrote in message
...
I'm trying to open a workbook using a macro. I keep getting an error that

the file can't be found.
I have two files in the same directory:
Questions.xls
Admin.xls
The user opens questions.xls. When they have completed entering data, the

macro in questions.xls saves the file and copies one row into admin.xls. I
can't specify the path because this application is designed to be saved by
different people in different places so I don't know what the path will be.
I thought by putting both files in the same directory, the macro would know
where to find admin.xls. Here's my code:

Sub Complete()
'
' Save the users results, copies the summary information to the admin
'tool, saves the admin tool and closes it. Then it shows the user their
'results
'
ThisWorkbook.save
Sheets("Name ").Select
Rows("3:3").Select
Selection.Copy
Workbooks.Open Filename:="admin.xls"
Rows("1000:1000").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,

SkipBlanks:= _
False, Transpose:=False
Cells.Select
Selection.Sort Key1:=Range("A2"), Order1:=xlAscending,

Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
ActiveWorkbook.save
ActiveWindow.Close

The error message says admin.xls can not be found. Any suggestions?



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
How do I stop blank workbook from opening when opening an existing kjg Excel Discussion (Misc queries) 3 February 12th 10 09:36 PM
when opening an Excel Workbook, another blank workbook also opens Gord Dibben Excel Discussion (Misc queries) 0 October 12th 07 09:49 PM
when opening an Excel Workbook, another blank workbook also opens spmu Excel Discussion (Misc queries) 0 October 12th 07 01:46 PM
How to make the opening of a workbook conditional upon the opening of another workbook Marcello do Guzman Excel Programming 1 December 16th 03 06:09 AM
How to make opening of workbook conditional of opening of another workbook turk5555[_2_] Excel Programming 2 December 15th 03 11:07 PM


All times are GMT +1. The time now is 07:42 AM.

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"