+ Reply to Thread
Results 1 to 1 of 1

Need help with VBA Code for file name and window control

Hybrid View

  1. #1
    Registered User
    Join Date
    06-18-2012
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    4

    Need help with VBA Code for file name and window control

    I am developing a workbook that will serve as a template for multiple users. I am currently attempting to develop an auto-open code that will format the initial display of the worksheet. I have a code that, once finished running, will open 2 windows, displaying 2 separate worksheets. One window will be the worksheet for data input, the second window is for associated macro command buttons. I have 2 problems:

    1. When I wrote the code using the macro recorder feature, the resulting code includes the specific file name in the window command. For example, the first line of text reads:

    Windows("LatestPCA-012113-1.xlsm:1").Activate

    Whenever the user starts to use this template, they are to rename the file for their respective project. The Code however, does not recognize that new name. How do I re-write the code so that it recognizes the current file name, not the name of the template of origin?

    2. The Code is designed assuming there are already 2 windows open in the saved workbook. If the user saves the workbook after closing one of the open 2 windows, the Code will no longer work. The Code reads:

    Windows("LatestPCA-012113-1.xlsm:1").Activate
    ActiveWindow.Close

    As you can see, if there is only 1 window open, the above code immediately closes that single window, leaving nothing to display.

    How can I re-write this code to close one of the 2 windows, if there are 2 windows open in the saved documents, but to not close the window if there is only 1 window open?

    Thanks
    Last edited by rbaughman; 01-28-2013 at 01:19 PM. Reason: correcting typos

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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