+ Reply to Thread
Results 1 to 2 of 2

[SOLVED] Run-time error 1004

  1. #1
    ISA
    Guest

    [SOLVED] Run-time error 1004

    I use a macro to save an XLS workbook (created from an XLT template) to HTML
    format for our intranet. It works fine once, but the second time it opens the
    saved HTML file before running the macro, which causes the error:
    Run-time error '1004': You cannot save this workbook with the same name as
    another open workbook or add-in....
    I am running the macro from a new toolbar.

    How do I prevent the macro from opening the HTML file?

    Sub PostNEXTMonth()
    ' MoveToCalendarWorksheet
    ActiveWindow.ScrollWorkbookTabs Position:=xlFirst
    Sheets("CALENDAR").Select
    'save to folder
    ' ActiveWorkbook.Save
    ' publish worksheet to Intranet
    Application.DisplayAlerts = False
    ActiveWorkbook.SaveAs Filename:="\\intranet\OnCallDocs\OnCall-next.htm", _
    FileFormat:=xlHtml, ReadOnlyRecommended:=False, CreateBackup:=False
    Application.DisplayAlerts = True
    'close without saving
    ActiveWorkbook.Close saveChanges:=False
    ThisWorkbook.Saved = True
    'close Excel
    Application.Quit
    End Sub

  2. #2
    ISA
    Guest

    RE: Run-time error 1004

    Never mind. I added the macro to a text box in the template file, added code
    to delete the box before saving it to HTML, and it works every time now
    without any errors.


    "ISA" wrote:

    > I use a macro to save an XLS workbook (created from an XLT template) to HTML
    > format for our intranet. It works fine once, but the second time it opens the
    > saved HTML file before running the macro, which causes the error:
    > Run-time error '1004': You cannot save this workbook with the same name as
    > another open workbook or add-in....
    > I am running the macro from a new toolbar.
    >
    > How do I prevent the macro from opening the HTML file?
    >
    > Sub PostNEXTMonth()
    > ' MoveToCalendarWorksheet
    > ActiveWindow.ScrollWorkbookTabs Position:=xlFirst
    > Sheets("CALENDAR").Select
    > 'save to folder
    > ' ActiveWorkbook.Save
    > ' publish worksheet to Intranet
    > Application.DisplayAlerts = False
    > ActiveWorkbook.SaveAs Filename:="\\intranet\OnCallDocs\OnCall-next.htm", _
    > FileFormat:=xlHtml, ReadOnlyRecommended:=False, CreateBackup:=False
    > Application.DisplayAlerts = True
    > 'close without saving
    > ActiveWorkbook.Close saveChanges:=False
    > ThisWorkbook.Saved = True
    > 'close Excel
    > Application.Quit
    > End Sub


+ 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