KenNichols Posted June 2, 2009 Posted June 2, 2009 Is there a way to loop this, so everytime you enter a file name that exists it brings up another InputBox? #include <Word.au3> Global $CustName = "ABC Company Inc" Global $sFilePath = @ScriptDir & "\New Microsoft Word document.doc" Global $oWordApp = _WordCreate($sFilePath,"",0) Global $oDoc = _WordDocGetCollection($oWordApp, 0) $oDoc.Range.Text = "This is some text." $FileName = StringLeft($CustName,30) If Not FileExists(@ScriptDir & "\" & $FileName & ".doc") Then _WordDocSaveAs ($oDoc, @ScriptDir & "\" & $FileName & ".doc") _WordQuit ($oWordApp) ElseIf FileExists(@ScriptDir & "\" & $FileName & ".doc") Then $NewFileName = InputBox("Error: File Exists","Please input a new file name!",StringLeft($CustName,30),"",250,125) $error = @error If $error = 1 Then ;<==Cancel was pressed _WordQuit ($oWordApp,0) EndIf $OldFileName = $NewFileName If FileExists(@ScriptDir & "\" & $NewFileName & ".doc") Then ; <=== Is there a way to loop this? $NewFileName = InputBox("Error: File Exists","THE FILE WILL BE OVERWRITTEN!",$OldFileName,"",250,125) $error = @error If $error = 1 Then ;<==Cancel was pressed _WordQuit ($oWordApp,0) EndIf EndIf $FileName = $NewFileName & ".doc" _WordDocSaveAs ($oDoc, @ScriptDir & "\" & $FileName) _WordQuit ($oWordApp) EndIf [topic="21048"]New to AutoIt? Check out AutoIt 1-2-3![/topic] Need to make a GUI? You NEED KODA FormDesigner!
stampy Posted June 2, 2009 Posted June 2, 2009 #include <Word.au3> Global $CustName = "ABC Company Inc" Global $sFilePath = @ScriptDir & "\New Microsoft Word document.doc" Global $oWordApp = _WordCreate($sFilePath,"",0) Global $oDoc = _WordDocGetCollection($oWordApp, 0) $oDoc.Range.Text = "This is some text." $FileName = StringLeft($CustName,30) If Not FileExists(@ScriptDir & "\" & $FileName & ".doc") Then _WordDocSaveAs ($oDoc, @ScriptDir & "\" & $FileName & ".doc") _WordQuit ($oWordApp) ElseIf FileExists(@ScriptDir & "\" & $FileName & ".doc") Then $NewFileName = InputBox("Error: File Exists","Please input a new file name!",StringLeft($CustName,30),"",250,125) $error = @error If $error = 1 Then ;<==Cancel was pressed _WordQuit ($oWordApp,0) EndIf $OldFileName = $NewFileName Do $NewFileName = InputBox("Error: File Exists","THE FILE WILL BE OVERWRITTEN!",$OldFileName,"",250,125) If @error Then _WordQuit($oWordApp,0) Exit EndIf Until Not FileExists(@ScriptDir & "\" & $NewFileName & ".doc") $FileName = $NewFileName & ".doc" _WordDocSaveAs ($oDoc, @ScriptDir & "\" & $FileName) _WordQuit ($oWordApp) EndIf
KenNichols Posted June 2, 2009 Author Posted June 2, 2009 Thanks! [topic="21048"]New to AutoIt? Check out AutoIt 1-2-3![/topic] Need to make a GUI? You NEED KODA FormDesigner!
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now