|
-
Nov 22nd, 2011, 06:12 PM
#1
Thread Starter
New Member
[Excel] Opening other workbooks
Hi,
I'm fairly new to VBA, but have used other languages before, and I'm trying to open a second workbook and copy data across from it.
To try and teach myself this, I tried to just open a second workbook and write to it but it's not working. I also tried to add some message prompts to see how far it's getting, but they are not appearing as well. (Though the second work book does open on the screen)
My code is:
Code:
Sub Copy()
FileToOpen = Application.GetOpenFilename _
(Title:="Please choose a file to import", _
FileFilter:="Excel Files *.xls (*.xls),")
Set wbk = Workbooks.Open(FileToOpen)
MsgBox "Test2"
wbk.Sheets("Sheet1").Range("E16").Value = "Bob"
MsgBox "Test"
End Sub
Thanks for any help,
Paul
-
Nov 22nd, 2011, 08:24 PM
#2
Hyperactive Member
Re: [Excel] Opening other workbooks
Try this to get the file name:
Code:
filetoopen = Application.GetOpenFilename _
("Excel Files (*.xls), *.xls", _
, "Please choose a file to import!")
-
Nov 23rd, 2011, 12:39 AM
#3
-
Nov 24th, 2011, 05:35 PM
#4
Thread Starter
New Member
Re: [Excel] Opening other workbooks
Thanks for your help.
Changing the open command to Workbooks.Open(filetoopen, True, True) seems to have sorted it.
Thanks,
Paul
-
Nov 25th, 2011, 04:25 AM
#5
Re: [Excel] Opening other workbooks
the second true is to open readonly
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|