+ Reply to Thread
Results 1 to 2 of 2

Open file with a variable name

  1. #1
    Registered User
    Join Date
    02-23-2007
    Posts
    1

    Open file with a variable name

    Hi all

    Newbie posting, please be gentle

    I am hoping that you excel wizards will be able to help me out. I got the basis of the code below online in a free excel help webpage.

    The code checks to see if a particular excel file is open and if it is then calls another macro (to copy and past some of the contents of the target file) into action.

    However what I want to do is to make the file name which is checked for variable - ie in the example below as long as "2830 V 6 dec 05.xls" OR "2830 V 6 dec 06.xls" (or any other year) is open then the 'CopyInfo' macro should be called.

    Many thanks in advance





    Sub IsWorkBookOpenDec()


    'Test to see if a Workbook is open.


    Dim wBook As Workbook

    On Error Resume Next
    Set wBook = Workbooks("2830 V 6 Dec.xls")

    If wBook Is Nothing Then 'Not open
    Range("f3").Select
    MsgBox "'2830 V 6 Dec.xls' is not open", _
    vbCritical, ""
    Set wBook = Nothing
    On Error GoTo 0
    Else 'It is open
    Call CopyInfo
    On Error GoTo 0
    End If
    End Sub

  2. #2
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    Variables added

    You will need to add the correct coding to set the sfname variable to the required book name. I have set it using the book name from your posted macro


    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1