Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default variable 'open' command

Hi Guys

I have the following problem:
I have to copy data from one excelfile (1.xls) to another
(summery.xls). No problem so far. it looks like

Workbooks.Open ("c:\[...]\1.xls")
Windows("1.xls").Activate

But now the path and the file itself changes! i need some kind of
query to tell to program which file it should use.

I couldn't find anything in the helpfiles which are not helpful at
all, btw.

Help is very much appreciated!
Walt
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default variable 'open' command

Does this mean that C:\...\1.xls can change name and location?

If yes, you can ask the user to just click on the file using the File|open
dialog.

Option Explicit
Sub testme()

Dim myFileName As Variant
Dim myWkbk As Workbook

myFileName = Application.GetOpenFilename("Excel files, *.xls")
If myFileName = False Then
'user hit cancel
Exit Sub '??
End If

Set myWkbk = Workbooks.Open(Filename:=myFileName)

'Now you can refer to the variable mywkbk instead of the actual name.
mywkbk.worksheets(1).range("A1").value = date
mywkbk.close savechanges:=true

End Sub

Walt wrote:

Hi Guys

I have the following problem:
I have to copy data from one excelfile (1.xls) to another
(summery.xls). No problem so far. it looks like

Workbooks.Open ("c:\[...]\1.xls")
Windows("1.xls").Activate

But now the path and the file itself changes! i need some kind of
query to tell to program which file it should use.

I couldn't find anything in the helpfiles which are not helpful at
all, btw.

Help is very much appreciated!
Walt


--

Dave Peterson

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default variable 'open' command

Thx, Dave. That helped a lot! But there is still a problem. If I try
(as Henry and I thought would be possible)

Workbooks("myWkbk").Activate

i get an error message:

"Run-time error '9': Subscript out of range"

Any clue for that one?

TIA
Walt

Dave Peterson wrote in message ...
Does this mean that C:\...\1.xls can change name and location?

If yes, you can ask the user to just click on the file using the File|open
dialog.

Option Explicit
Sub testme()

Dim myFileName As Variant
Dim myWkbk As Workbook

myFileName = Application.GetOpenFilename("Excel files, *.xls")
If myFileName = False Then
'user hit cancel
Exit Sub '??
End If

Set myWkbk = Workbooks.Open(Filename:=myFileName)

'Now you can refer to the variable mywkbk instead of the actual name.
mywkbk.worksheets(1).range("A1").value = date
mywkbk.close savechanges:=true

End Sub

Walt wrote:

Hi Guys

I have the following problem:
I have to copy data from one excelfile (1.xls) to another
(summery.xls). No problem so far. it looks like

Workbooks.Open ("c:\[...]\1.xls")
Windows("1.xls").Activate

But now the path and the file itself changes! i need some kind of
query to tell to program which file it should use.

I couldn't find anything in the helpfiles which are not helpful at
all, btw.

Help is very much appreciated!
Walt

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default variable 'open' command

Hi Walt,

Your problem statement is a bit vague. How is the program
supposed to determine the file name?

David Gray
P6 Consulting
http://www.p6c.com

You are more important than any technology we may employ.



-----Original Message-----
But now the path and the file itself changes! i need some

kind of
query to tell to program which file it should use.

I couldn't find anything in the helpfiles which are not

helpful at
all, btw.


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
Will only open with FileOpen Command qforgues Excel Discussion (Misc queries) 0 January 11th 11 05:59 PM
Open a Workbook using a Command Button aussiegirlone Excel Discussion (Misc queries) 2 April 7th 09 03:56 AM
Variable Or Command str83dgeboi Excel Worksheet Functions 7 November 13th 08 07:42 PM
SUM command using variable sheets IanC Excel Worksheet Functions 3 May 18th 07 11:56 PM
Problem with Excel-VBA - Open Command after SP3 Wolfgang Wagner Excel Discussion (Misc queries) 1 June 1st 05 01:25 PM


All times are GMT +1. The time now is 10:12 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"