Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
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
Getting started tab saphire New Users to Excel 7 June 12th 07 08:57 PM
VBA Getting Started PaulW Excel Discussion (Misc queries) 1 March 30th 06 02:59 PM
Getting Started Jeff Bendert Excel Programming 1 March 10th 06 04:05 PM
Need help getting started phreud[_25_] Excel Programming 3 November 18th 04 01:13 PM
Need help getting started phreud[_26_] Excel Programming 0 November 18th 04 12:45 PM


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