Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Why it can work in Function but ok in Sub

Can anyone tell me why the following code cannot work in Function but ok in
a Sub?
In Function, the statement
Workbooks("testing.xls").Activate
doesn't work, but ok in Sub

Thanks

Function no_of_HK_working_day(date1 As Date, date2 As Date, half_sat As
Double)

Set wb_current = ActiveWorkbook
Workbooks("testing.xls").Activate
Set wb_holiday = ActiveWorkbook
wb_current.Activate

End Function


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Why it can work in Function but ok in Sub

Do you mean running that function from a worksheet? If so, it is because
worksheet functions cannot make changes to the workbook or worksheets other
than returning a value to that cell.

If you ran that function from within VBA, it should work okay.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"new.microsoft.com" wrote in message
...
Can anyone tell me why the following code cannot work in Function but ok

in
a Sub?
In Function, the statement
Workbooks("testing.xls").Activate
doesn't work, but ok in Sub

Thanks

Function no_of_HK_working_day(date1 As Date, date2 As Date, half_sat As
Double)

Set wb_current = ActiveWorkbook
Workbooks("testing.xls").Activate
Set wb_holiday = ActiveWorkbook
wb_current.Activate

End Function




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
Why won't this function work? Angelsnecropolis Excel Worksheet Functions 3 March 12th 10 05:00 AM
Function doesn't work Neal Carron[_2_] Excel Worksheet Functions 2 January 26th 10 02:11 AM
need a function that will work using multiple work books and sheet capt c Excel Worksheet Functions 1 March 30th 09 10:20 PM
Why does my Function not work? [email protected] Excel Discussion (Misc queries) 2 April 27th 07 10:22 PM
function doesn't work Claude Excel Programming 1 December 11th 03 08:48 PM


All times are GMT +1. The time now is 07:05 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"