ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   VBA - Testing for Book1, Book2 etc. (https://www.excelbanter.com/excel-discussion-misc-queries/231661-vba-testing-book1-book2-etc.html)

dhstein

VBA - Testing for Book1, Book2 etc.
 
Every day Quickbooks will create an excel file and depending on what is going
on on the user's system, it may be created as Book1, Book2 etc. In another
file on the user's machine, I'd like to create a macro that will save that
file to the network with a specific name. So I need a way of testing if
there is an open workbook called Book1, Book2 etc. There will only be one
Bookx file so if I find anything Bookx that's the one I need. Thanks for any
help on this.

Jacob Skaria

VBA - Testing for Book1, Book2 etc.
 
Paste the below function in your code and use it as

If Checkforworkbook ("Book25.xls") = True Then
'do something
End If

Function CheckforWorkbook(strSearch As String) As Boolean
Dim intTemp
For intTemp = 1 To Workbooks.Count
If InStr(1, Workbooks(intTemp).Name, strSearch, 1) < 0 Then
CheckforWorkbook = True: Exit Function
End If
Next
End Function
--
If this post helps click Yes
---------------
Jacob Skaria


"dhstein" wrote:

Every day Quickbooks will create an excel file and depending on what is going
on on the user's system, it may be created as Book1, Book2 etc. In another
file on the user's machine, I'd like to create a macro that will save that
file to the network with a specific name. So I need a way of testing if
there is an open workbook called Book1, Book2 etc. There will only be one
Bookx file so if I find anything Bookx that's the one I need. Thanks for any
help on this.



All times are GMT +1. The time now is 10:15 PM.

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