myran1178 Posted October 28, 2018 Share Posted October 28, 2018 Hello all! I am new to Autoit! Tried it for first time yesterday! Only the beginning of my script is done and I need help with figuring out the rest of the code. My autoit script below: #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.14.5 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here $input = InputBox ("filnamn", "Vad ska dokumentet heta?") $FILNAMN = $input $Fil="$FILNAMN.docx" #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.14.5 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- What I want my script to do when finished: Create a new .docx file using the variable $FILNAMN as the filename. Open the created file in a new Microsoft Word window Simulate the Ctrl+s keyboard shortcut inside the active MS Word window Any kind of help is worth gold! Have a great Sunday! Bye myran1178 Link to comment Share on other sites More sharing options...
myran1178 Posted October 28, 2018 Author Share Posted October 28, 2018 I forgot to say that if someone knows a better forum for this topic, feel free to move it. Link to comment Share on other sites More sharing options...
water Posted October 28, 2018 Share Posted October 28, 2018 Welcome to AutoIt and the forum! AutoIt comes with an UDF for MS Word. Please have a look at _Word_DocAdd to create a new document. To save the file use function _Word_DocSaveAs. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
myran1178 Posted October 28, 2018 Author Share Posted October 28, 2018 Hi! Thank for a quick reply! Let me think about it! myran1178 Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted October 29, 2018 Moderators Share Posted October 29, 2018 @myran1178 I see here that water gave you a good suggestion on how to move forward with your script. You must not have "thought about it" too hard, as you were PM'ing this exact question to me this morning. Please follow the suggestions you receive from forum members and try things out rather than expecting others to simply fix it for you. Once you have tried something, think of this forum as math class and show your work. Danp2, Earthshine and TheXman 3 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
myran1178 Posted October 29, 2018 Author Share Posted October 29, 2018 @water Hello Water! How would _Word_DocAdd and _Word_DocSaveAs look in my code? Wondering cause I dont know how to put _Word_DocAdd and _Word_DocAdd and _Word_DocSaveAs inside my code! Great Monday afternoon Water! (My clock is 4pm where I live!) Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted October 29, 2018 Moderators Share Posted October 29, 2018 @myran1178 again, what have you tried? _Word_DocAdd has an excellent example script in the help file, which you should be able to modify very simply to suit your needs. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
myran1178 Posted October 29, 2018 Author Share Posted October 29, 2018 (edited) @JLogan3o13 I can not remember all of what I tried but I tried many that I found in different sources when I looked around on internet. Can you see any error below? #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.14.5 Author: myName Script Function:#ce Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here $input = InputBox ("filnamn", "Vad ska dokumentet heta?") $FILNAMN = $input #include <MsgBoxConstants.au3> #include <Word.au3> Local $oWord = _Word_Create() If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocAdd Example", _ "Error creating a new Word application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) ; Add a new empty document _Word_DocAdd($oWord) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocAdd Example", "Error creating a new Word document." _ & @CRLF & "@error = " & @error & ", @extended = " & @extended) MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocAdd Example", "A new empty document has successfully been added.") #include <Word.au3> _Word_DocSaveAs ( $oDoc [, $sFileName = Default [, $iFileFormat = $WdFormatDocument [, $bReadOnlyRecommended = False [, $bAddToRecentFiles = True [, $sPassword = "" [, $sWritePassword = ""]]]]]] ) SciTe found a error in the _Word_DocSaveAs part but I dont understand what SciTE thinks is wrong! Edited October 29, 2018 by Melba23 Added code tags Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 29, 2018 Moderators Share Posted October 29, 2018 myran1178, When you post code in future please use Code tags - see here how to do it. Then you get a scrolling box and syntax colouring as you can see above now I have added the tags. Thanks in advance for your cooperation. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted October 29, 2018 Moderators Share Posted October 29, 2018 21 minutes ago, myran1178 said: SciTe found a error in the _Word_DocSaveAs part but I dont understand what SciTE thinks is wrong! Are you using the full SciTe install? What is the output in the console pane at the bottom, showing the error? "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
myran1178 Posted October 29, 2018 Author Share Posted October 29, 2018 I am using SciTE Lite. copied from the console: >"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Users\mirbyg1\Desktop\Ny(tt) AutoIt v3 Script.au3" "C:\Users\mirbyg1\Desktop\Ny(tt) AutoIt v3 Script.au3" (27) : ==> Variable used without being declared.: _Word_DocSaveAs ( $oDoc [, $sFileName = Default [, $iFileFormat = $WdFormatDocument [, $bReadOnlyRecommended = False [, $bAddToRecentFiles = True [, $sPassword = "" [, $sWritePassword = ""]]]]]] ) _Word_DocSaveAs ( ^ ERROR >Exit code: 1 Time: 14.34 Link to comment Share on other sites More sharing options...
myran1178 Posted October 29, 2018 Author Share Posted October 29, 2018 @MeIba23 I have been used the <> button before. Did it when I created this topic. I am doing it everytime I ad code in my comments! When I wrote the comment you referred to , something wrong happened when I used the <> button,(dont ask what happened) so I decided to copypaste it normally instead. The comment you referred to was a exception. Link to comment Share on other sites More sharing options...
water Posted October 29, 2018 Share Posted October 29, 2018 The syntax is wrong. Brackets denote optional parameters. Remove them if you set the parameter. $variable = value needs to be replaced just with the value you want to use for this parameter. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
myran1178 Posted October 29, 2018 Author Share Posted October 29, 2018 Which variable did u referred to? Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted October 29, 2018 Moderators Share Posted October 29, 2018 _Word_DocSaveAs ( $oDoc [, $sFileName = Default [, $iFileFormat = $WdFormatDocument [, $bReadOnlyRecommended = False [, $bAddToRecentFiles = True [, $sPassword = "" [, $sWritePassword = ""]]]]]] ) Is not how it is shown in the example in the help file: _Word_DocSaveAs($oDoc, @TempDir & "\_Word_Test2.doc") You need to think through what you are trying to do here: ;From you script above ; Script Start - Add your code below here $input = InputBox ("filnamn", "Vad ska dokumentet heta?") $FILNAMN = $input #include <MsgBoxConstants.au3> #include <Word.au3> Local $oWord = _Word_Create() If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocAdd Example", _ "Error creating a new Word application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) ; Add a new empty document _Word_DocAdd($oWord) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocAdd Example", "Error creating a new Word document." _ & @CRLF & "@error = " & @error & ", @extended = " & @extended) MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocAdd Example", "A new empty document has successfully been added.") #include <Word.au3> _Word_DocSaveAs ( $oDoc [, $sFileName = Default [, $iFileFormat = $WdFormatDocument [, $bReadOnlyRecommended = False [, $bAddToRecentFiles = True [, $sPassword = "" [, $sWritePassword = ""]]]]]] ) Line 14: _Word_DocAdd($oWord) - You don't specify a Variable for this, so how can you reference it later???? Line 18: #include <Word.au3> - You already included this at the top of your script, why are you doing it again??? Line 19: _Word_DocSaveAs ( $oDoc [, $sFileName = Default [, $iFileFormat = $WdFormatDocument [, $bReadOnlyRecommended = False [, $bAddToRecentFiles = True [, $sPassword = "" [, $sWritePassword = ""]]]]]] ) You do not specify a $oDoc variable in your script, so no big surprise why _Word_DocSaveAs is failing. You don't specify a filename, so _Word_DocSaveAs doesn't know where to save it, even if you DID have a variable to reference. If you aren't changing the $iFileFormat, $bReadOnlyRecommended, $bAddToRecentFiles, $sPassword, or $sWritePassword variables, which I would suggest you do not until you figure out the basics, just omit them. As was mentioned, remove the brackets So, your line 19 should really look exactly like what the example script shows, you just need to set your _Word_DocAdd to a variable. We know you want to get your first script done, but you need to slow down and actually read the help file rather than just copying and pasting a bunch of lines you do not understand and then posting when it doesn't work. Xandy and FrancescoDiMuro 2 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
myran1178 Posted October 30, 2018 Author Share Posted October 30, 2018 @JLogan3o13 Thank you for a very detailed answer! Link to comment Share on other sites More sharing options...
myran1178 Posted November 4, 2018 Author Share Posted November 4, 2018 (edited) Hello! I showed you my script code and told you my goals with my script in the first post but I forgot to tell the story behind my script. I will therefore tell you the story behind my script code in this post! The code inside the code box of the first post was the result of me trying to recreate a bat file. I worked on my batch file WC2018.bat last Saturday but later the same day, after many Google searches and trying few languages, I decided to try Autoit instead. Then (still last Saturday), I tried to recreate the batch file in Autoit but the next day(last Sunday) after had been working hard with it in two days, I only succeeded with figuring out Autoit´s equivalent to the user input box in the beginning of WC2018.bat . The rest of the WC2018.bat was too dificult to figure out. Therefore, I created this thread last Sunday bacuse I needed help with recreating the rest of the bat file. Now, when you knows the story behind it, please suggest how I can recreate the rest of the bat file! I want my autoit script to do the same things as the bat file and I need help with that Edited November 4, 2018 by myran1178 Forgot to add something at the end Link to comment Share on other sites More sharing options...
Developers Jos Posted November 4, 2018 Developers Share Posted November 4, 2018 So something like this?: Global $Filename = "" While $filename = "" $Filename=InputBox("new Document","Enter the new Document filename") If @error then ; Cancel pressed - Exit script Exit EndIf WEnd FileWrite($filename&".docx","") ShellExecute("WinWord",$filename&".docx") Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
myran1178 Posted November 4, 2018 Author Share Posted November 4, 2018 6 hours ago, Jos said: So something like this?: Global $Filename = "" While $filename = "" $Filename=InputBox("new Document","Enter the new Document filename") If @error then ; Cancel pressed - Exit script Exit EndIf WEnd FileWrite($filename&".docx","") ShellExecute("WinWord",$filename&".docx") Jos Did you mixed $Filename and $filename on purpose or did it just happened? Link to comment Share on other sites More sharing options...
Developers Jos Posted November 4, 2018 Developers Share Posted November 4, 2018 Just now, myran1178 said: Did you mixed $Filename and $filename on purpose or did it just happened? Just so happened and didn't run Tidy on it to "fix" that, but AutoIt3 isn't case sensitive, so script will still work. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
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