View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Gert-Jan[_2_] Gert-Jan[_2_] is offline
external usenet poster
 
Posts: 29
Default File open and close, get some data

The situation:

In file test.xls

sheet1A1: in a formula there is the filename (including dir). For example:
C:\test\test.xls
sheet1A2: in a formula there is the filename of data.xls (including dir).
For example: C:\test\data.xls

The files are placed with a setup, so the dir "test" can be changed to
anything the user prefers.

In file data.xls (password protected, "ABC"):

sheet1B4:D20: some data I want to copy. Destination: test.xls sheet2 C1:E16,
so: selection cell: C1.

I would like to know how to write macro that opens data.xls, copies the data
to test.xls, closes data.xls.

I have this (nor ready yet), but an error occured. The first part (opening
and copying) works fine.

Sub Macro1()
Dim GJ
GJ = Range("Sheet1!A1").Value
Dim GJ2
GJ2 = Range("Sheet1!A2").Value
Workbooks.Open Filename:=GJ, Password:="XYZ"
Range("B4:D20").Select
Selection.Copy
'this doesn't work:
Workbooks ("GJ2").Activate
Range("C1").Select
Selection.PasteSpecial Paste:=xlPasteValues
End Sub

Thanks for helping!