+ Reply to Thread
Results 1 to 8 of 8

How to open a new workbook every time the macro executes

  1. #1
    Registered User
    Join Date
    09-19-2008
    Location
    Singapore
    Posts
    41

    How to open a new workbook every time the macro executes

    Hi All,

    I have a code where I am opening a new file every time the macro executes. How can I write a check in VBA to over write the file if it already exists.

    Please Login or Register  to view this content.
    UniqueIssueTypeList(temp_i) gives me the file name for e.g. File1

    Cheers,
    Aswathy

  2. #2
    Forum Contributor Stuie's Avatar
    Join Date
    09-17-2006
    Location
    Suffolk, UK
    MS-Off Ver
    Excel 2003/2007
    Posts
    432
    Hi Aswathy,

    What exactly do you mean by overwrite?? do you mean to save it and overwrite origanal file or close the file if its open and then open this one??
    There are only 10 types of people in the world:
    Those who understand binary, and those who don't!

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    You need to create a template workbook, see

    http://www.excel-it.com/excel_templates.htm
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  4. #4
    Registered User
    Join Date
    09-19-2008
    Location
    Singapore
    Posts
    41
    Hi Roy,

    Thanks for the heads up. What I meant was the file may not be open all the time I try to write data into it. If the file exists in that location, then writing of data, shouldn't be appending to the original one but rewriting the whole file.

    I hope I made it clear this time

    Please Login or Register  to view this content.
    My approach to this is the code written above, I want to know like in many other languages, does VBA support opening of a file in over-write mode.

    Cheers,
    Aswathy
    Last edited by Aswathy; 10-22-2008 at 06:13 AM.

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    You need a Function to check if the file exists, see my posted code here

    http://www.excelforum.com/excel-prog...ts-method.html

  6. #6
    Registered User
    Join Date
    09-19-2008
    Location
    Singapore
    Posts
    41
    Hi Roy,

    I already had a look at this piece of code I was already doing the same thing, the else part if the fileExists was my concern.

    Cheers,
    Aswathy

  7. #7
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Do you mean
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    09-19-2008
    Location
    Singapore
    Posts
    41
    Hi Roy,

    The saveCopyAs will create another copy of the existing file, isn't it. The thing is I am creating let say 4 files like this, so every time when the user runs the macro it will create a new one with the file name suffixed with the current date. I feel this is not needed since the older versions of the file data will be obsolete. That is why I am trying to reuse the same file.

    Cheers,
    Aswathy

+ 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