Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Help - Code not always working

Have a macro unsed by many people to append information their worksheet to
another worksheet called 'Master.xls'. At the end of the day, the Master.xls
is renamed for batch process. So at the start of each day the the first
person who tries to update the Master.xls creates it.

Been using the below code being used to check if the master.xls worksheet
already exist. Problem is it does not always work. Sometimes the result
for the code '.Execute 1' will be true, others times result is false, the
Master file exist in both instances. Any suggestion on how to correct?

'Test to see if a Workbook exists
''''''''''''''''''''''''''''''''
Dim i As Integer

With Application.FileSearch
.LookIn = "\\s1racft1\public\PreventativeExpedite"
.Filename = "Master.xls"
If .Execute 1 Then 'Workbook exists, open the workbook
Workbooks.Open
Filename:="\\server\public\PreventativeExpedite\Ma ster.xls"
Else 'There is not a Workbook, create a new workbook
Set NewBook = Workbooks.Add
With NewBook
.Title = "Master"
.SaveAs
Filename:="\\server\public\PreventativeExpedite\Ma ster.xls"
End With
End If
End With
End Sub


Thank you.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Help - Code not always working

Here is some un-tested code but it might give you some ideas...

Public Function ReturnMaster() as workbook
dim wbkReturn as workbook
on error resume next
set wbkReturn = workbooks("master.xls")
if wbkReturn is nothing then
set wbkReturn = workbooks.open("\\s1racft1" & _
"\public\PreventativeExpedite\master.xls")
end if
if wbkReturn is nothing then
set wbkReturn = workbooks.add
wbkreturn.saveas("\\s1racft1\public\PreventativeEx pedite\master.xls")
end if
set ReturnMaster = wbkReturn
end function
--
HTH...

Jim Thomlinson


"twperplex" wrote:

Have a macro unsed by many people to append information their worksheet to
another worksheet called 'Master.xls'. At the end of the day, the Master.xls
is renamed for batch process. So at the start of each day the the first
person who tries to update the Master.xls creates it.

Been using the below code being used to check if the master.xls worksheet
already exist. Problem is it does not always work. Sometimes the result
for the code '.Execute 1' will be true, others times result is false, the
Master file exist in both instances. Any suggestion on how to correct?

'Test to see if a Workbook exists
''''''''''''''''''''''''''''''''
Dim i As Integer

With Application.FileSearch
.LookIn = "\\s1racft1\public\PreventativeExpedite"
.Filename = "Master.xls"
If .Execute 1 Then 'Workbook exists, open the workbook
Workbooks.Open
Filename:="\\server\public\PreventativeExpedite\Ma ster.xls"
Else 'There is not a Workbook, create a new workbook
Set NewBook = Workbooks.Add
With NewBook
.Title = "Master"
.SaveAs
Filename:="\\server\public\PreventativeExpedite\Ma ster.xls"
End With
End If
End With
End Sub


Thank you.

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
VB Code Is Not Working Rob Excel Discussion (Misc queries) 2 May 30th 07 05:23 PM
Pop up code not working Ian Manning Excel Programming 3 April 3rd 06 05:48 PM
Wht is this Code not Working ? John Excel Programming 7 December 7th 04 02:09 AM
Vb Code not working bob Excel Programming 3 January 5th 04 01:29 PM
Code not working Bob Phillips[_5_] Excel Programming 5 August 14th 03 03:12 PM


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