Jump to content

Help me to continue my autoit script


Recommended Posts

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

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

  • Moderators

@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.

"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

  • Moderators

@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

@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 by Melba23
Added code tags
Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators
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

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

  @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

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

  • Moderators

:rolleyes:

_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.

"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

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 by myran1178
Forgot to add something at the end
Link to comment
Share on other sites

  • Developers

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

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

  • Developers
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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...