Jump to content

Recommended Posts

I have an excel file which saves a copy of itself using the following:


Sub SaveFile()

Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:="C:\Users\" & Environ$("username") & _
    "\Desktop\" & "DEP " & Range("A4").Text & Chr(32) & Format(Now(), "MMM-DD-YY hh mm ss") & ".xlsm", _
    FileFormat:=52, CreateBackup:=False
Application.DisplayAlerts = True


End Sub

This works fine, except that SOMETIMES I cannot attach to the newly created file with BookAttach. Only the first copy created has the problem, and I don't know why. If I make another copy, or even rename the filename, it suddenly works. (I've tried testing for various date/times on my filename, and could not find any pattern.) I also notice that this does not happen when workbooks are saved as .xlsx (no macros). The autoit code is below. You'll notice that _ArrayDisplay will return nothing.


     $sTitle = WinGetTitle("[active]")
    If StringInStr($sTitle, "dep") = 0 Then Return MsgBox(0, @ScriptName, 'Line ' & @ScriptLineNumber & @CRLF & 'Cant find Window')
    $oWorkbook = _Excel_BookAttach($sTitle, 'Title')

Global $aResult = _Excel_RangeRead($oWorkbook, Default, "A4:H37", 1)
   _ArrayDisplay($aResult)

Edited by centagon
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...