Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Getting started
I'm just starting out...
How do I get my macro to use the active worksheet. before I used the filename: With Workbooks("Calculatron.xls") but I had two copies of the file, and the macro would only work in the original file. thank you... |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Getting started
Your with statement is actually pointing at that specific workbook.
You can use this: with activeworkbook (for the workbook) or with activesheet (for the active sheet) newbie wrote: I'm just starting out... How do I get my macro to use the active worksheet. before I used the filename: With Workbooks("Calculatron.xls") but I had two copies of the file, and the macro would only work in the original file. thank you... -- Dave Peterson |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Getting started
Thanks Dave,
I've tried both methods and they didn't work. I also changed the filename and it doesn't make a difference. It says the file cannot be accessed. This file is on a netork hard-drive. The original on my external hard drive works fine. What do you think? newbie Dave Peterson wrote: Your with statement is actually pointing at that specific workbook. You can use this: with activeworkbook (for the workbook) or with activesheet (for the active sheet) newbie wrote: I'm just starting out... How do I get my macro to use the active worksheet. before I used the filename: With Workbooks("Calculatron.xls") but I had two copies of the file, and the macro would only work in the original file. thank you... -- Dave Peterson |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Getting started
If you want your code to act on the data on the activesheet, then that workbook
has to be open--and the correct sheet has to be active. If your code needs to open the workbook to work on it, you can include that in your procedure, too. dim myFileName as Variant dim Wkbk as workbook dim wks as worksheet myfilename = Application.GetOpenFilename(filefilter:="Excel Files, *.xls") if myfilename = false then 'user hit cancel exit sub end if set wkbk = workbooks.open(filename:=myfilename) set wks = wkbk.worksheets("sheet1") 'whichever you want with wks 'do stuff end with wkbk.close savechanges:=true newbie wrote: Thanks Dave, I've tried both methods and they didn't work. I also changed the filename and it doesn't make a difference. It says the file cannot be accessed. This file is on a netork hard-drive. The original on my external hard drive works fine. What do you think? newbie Dave Peterson wrote: Your with statement is actually pointing at that specific workbook. You can use this: with activeworkbook (for the workbook) or with activesheet (for the active sheet) newbie wrote: I'm just starting out... How do I get my macro to use the active worksheet. before I used the filename: With Workbooks("Calculatron.xls") but I had two copies of the file, and the macro would only work in the original file. thank you... -- Dave Peterson -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Getting started tab | New Users to Excel | |||
VBA Getting Started | Excel Discussion (Misc queries) | |||
Getting Started | Excel Programming | |||
Need help getting started | Excel Programming | |||
Need help getting started | Excel Programming |