ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   startup macro problem (https://www.excelbanter.com/excel-programming/299265-startup-macro-problem.html)

Scott

startup macro problem
 
Need your help.

I have an Excel workbook that does specific
tasks automatically when it is started. I
have been trying to add one more task but
am having real problems doing so.

What I want to do is to add code in my current
workbook startup macro that will go to the C:\
drive and look for a specific file (e.g. targetfile.xls)
at a specific location (e.g. C:\TARGET FOLDER\).
If the file is found at that specific location all I
want the macro to do is to put a value of "TRUE" on
worksheet 1 in cell A1. If the macro does not find the
file I want it to put a value of "FALSE" in cell A1. I
don't want any alerts or messages telling me that the
file could not be found, if that is the case.

I think my problems in getting this to work
thus far have been related to "error handling"
issues if the file is not found. I can't
seem to get the needed code right. Don't know if I
am experiencing brain cell loss or am simply getting
confused due to the noise from the Cicadas that have
taken over my neighborhood. Any help getting me back on
track will be greatly appreciated.

Chip Pearson

startup macro problem
 
Scott,

You can use code like

If Dir("C:\Target Folder\Target File.xls") = "" Then
' not found
Range("A1").Value = False
Else
' found
Range("A1").Value = True
End If


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"scott" wrote in message
...
Need your help.

I have an Excel workbook that does specific
tasks automatically when it is started. I
have been trying to add one more task but
am having real problems doing so.

What I want to do is to add code in my current
workbook startup macro that will go to the C:\
drive and look for a specific file (e.g. targetfile.xls)
at a specific location (e.g. C:\TARGET FOLDER\).
If the file is found at that specific location all I
want the macro to do is to put a value of "TRUE" on
worksheet 1 in cell A1. If the macro does not find the
file I want it to put a value of "FALSE" in cell A1. I
don't want any alerts or messages telling me that the
file could not be found, if that is the case.

I think my problems in getting this to work
thus far have been related to "error handling"
issues if the file is not found. I can't
seem to get the needed code right. Don't know if I
am experiencing brain cell loss or am simply getting
confused due to the noise from the Cicadas that have
taken over my neighborhood. Any help getting me back on
track will be greatly appreciated.





All times are GMT +1. The time now is 02:53 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com