Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA newbie question


How do you "execute" a VBA "function". I'm trying to use the following
code (found on the net) to check whether a file exists when a workbook
is activated. If the file doesn't exist I want to save a copy of the
workbook as a given name "Master Template".

Function FileExist(sTestFile As String) As Boolean

sTestFile = "C:\Business Cases\Master Template.xls"
Dim lSize As Long
On Error Resume Next
lSize = -1
lSize = FileLen(sTestFile)
If lSize < -1 Then

ActiveWorkbook.SaveAs Filename:="C:\ROI Business Cases\Master
Template.xls", FileFormat:= _
xlNormal, Password:="", WriteResPassword:="",
ReadOnlyRecommended:=False _
, CreateBackup:=False
End If

End Function


--
peter.thompson
------------------------------------------------------------------------
peter.thompson's Profile: http://www.excelforum.com/member.php...o&userid=29686
View this thread: http://www.excelforum.com/showthread...hreadid=501319

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 137
Default VBA newbie question

Hi Peter,

In case of a Function, just type in your function in any cell of your
worksheet ...

HTH
Cheers
Carim

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA newbie question


Thanks Carim, my learning is moving up a notch!

Cheers

Peter


--
peter.thompson
------------------------------------------------------------------------
peter.thompson's Profile: http://www.excelforum.com/member.php...o&userid=29686
View this thread: http://www.excelforum.com/showthread...hreadid=501319

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default VBA newbie question

That code does not need to be a function because it does not return a
result, which is the normal practice for a function. Also, I don't think you
should be using it within a worksheet as again it isn't returning a result,
so nothing shows in the cell.

I think you should be calling it from within another macro, probably from
within the Workbook_Open event.

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"peter.thompson"
<peter.thompson.21ma1y_1137229201.0676@excelforu m-nospam.com wrote in
message news:peter.thompson.21ma1y_1137229201.0676@excelfo rum-nospam.com...

Thanks Carim, my learning is moving up a notch!

Cheers

Peter


--
peter.thompson
------------------------------------------------------------------------
peter.thompson's Profile:

http://www.excelforum.com/member.php...o&userid=29686
View this thread: http://www.excelforum.com/showthread...hreadid=501319



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA newbie question


That is exactly what I have ended up doing, using different code that I
found on the net:

Dim fso
Dim file As String
file = "C:\ROI Business Cases\Master Template.xls" ' change to match
the file w/Path
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FileExists(file) Then
ActiveWorkbook.SaveAs Filename:="C:\ROI Business Cases\Master
Template.xls", FileFormat:= _
xlNormal, Password:="", WriteResPassword:="",
ReadOnlyRecommended:=False _
, CreateBackup:=False
End If


Cheers and thanks Bob

Peter


--
peter.thompson
------------------------------------------------------------------------
peter.thompson's Profile: http://www.excelforum.com/member.php...o&userid=29686
View this thread: http://www.excelforum.com/showthread...hreadid=501319

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
Newbie Question... Benjamin M New Users to Excel 6 May 27th 08 04:45 PM
Real Newbie newbie question Dave New Users to Excel 0 January 10th 07 07:55 PM
Newbie Question - Subtraction Formula Question [email protected] Excel Discussion (Misc queries) 3 May 5th 06 05:50 PM
Newbie question EdL Excel Programming 2 August 15th 04 10:52 PM
Newbie Question .. what's this stevem[_6_] Excel Programming 2 April 2nd 04 05:06 AM


All times are GMT +1. The time now is 12:45 PM.

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"