Jump to content

Insert footer text in a word document - (Moved)


Recommended Posts

 

Hi Guys,

I'm writing a script that loops through all the word documents in a given folder and inserts text into the footer.
This is mostly working great.

I have run into a problem where the footer in a few documents is somehow protected.
If I open word manually I can select the text in the footer but I can't add to it.
I can update the main text in the document so it isn't simply password protected.
Rather than try and unprotect it I'm happy just to skip over it.

I currently get an error on the line shown below $oRange.Inserafter

      ; Insert the text
      $oRange.Insertafter($text1 & $LastSavedDay &'/'& $LastSavedMonth &'/'& $LastSavedYear & $text2)
      If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Insert Modified Date", _
        "Error 010 Setting first footer InsertAfter location" & $file & @CRLF & "@error = " & @error & ", @extended = " & @extended)

"E:\FileConversion\InsertCreationDate2.au3" (120) : ==> The requested action with this object has failed.:
$oRange.Insertafter($text1 & $LastSavedDay &'/'& $LastSavedMonth &'/'& $LastSavedYear & $text2)
$oRange^ ERROR

It stops at the above line and does not get to the @error statement.

I guess what I really need is to catch this error and jump to the next document in my for next loop.

I'm happy to add the entire script to this post if anyone thinks that will help.

Any Ideas?

David

Link to post
Share on other sites

Add a COM error handler to your script. Check ObjEvent in the help file for details and examples. 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-11-10 - Version 1.6.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (NEW 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 (NEW 2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to post
Share on other sites
  • Moderators

Moved to the appropriate forum.

Moderation Team

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 post
Share on other sites
21 hours ago, water said:

Add a COM error handler to your script. Check ObjEvent in the help file for details and examples. 

Hi Water,

Thanks for the point in the right direction.  I managed to figure it out from the help once I knew were to look.

My script now warns the user of the files that can't be modified and carries on which is exactly what I want to happen :)

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.

  • Similar Content

    • By anoig
      Hi all, 

      First, I want to give a huge shout-out to the community. I'm completely self-taught, and have never had to actually ask a question before because the forum is that good at answering questions and explaining things. However, I'm kind of stumped here, and I've been stuck on this problem for almost a full day.

      I'm working on a script to populate drafts of deeds at work. I have the main GUI and  a function (ctrl($n) and read()) for adding fields to find and data to replace it with to an array for later use with _word_docfindreplace. All of that works. However, due to the way I have the forms set up, I need to create additional fields and info based on the data that's there. Specifically, if there's only one buyer, I need to add the field [Buyer1&2] and the data in $aArray_Base for [Buyer 1]. I also need to add a field [Buyer 2] and have a blank data set in the next column over in the array, and I need to do the same for the Seller. To this end, the function parties() sets boolean variables $2buyers and $2sellers accordingly. Then, I have buyers() and sellers() to populate the data. 

      The problem that I'm running into is that each function works... when ONLY the buyer 1 name field is filled, and when ONLY the seller 1 field is filled.

      So if I fill Buyer 1 Name and save it, the data is populated correctly. But when I fill Buyer 1 and Seller 1 name, only the buyer 1 data populates correctly. Worse, when I fill several fields, neither populate correctly. I have no idea why this happens. I've added messageboxes to debug throughout the entire process and can't pinpoint what's causing the issue. The entire script is below. The function(s) in question are buyers() and sellers(). Only Sellers() has messageboxes throughout.

      Can someone help walk me through what might be causing this and help me find a solution? Thanks a ton in advance, and sorry for the wall of text.
      -Anoig
       
    • By water
      My computer has been upgraded from Office 2010 to Office 2016.
      Are there any features of Office 2013 or Office 2016 which you now want to see in the Excel, Word or Outlook UDF?
    • By Jury
      As near as I can ascertain using the Word UDF the paragraph count does not count the numbered paragraphs in a document but counts something like all paragraphs (numbered , un-numbered, indented) minus empty lines.  Is there any easy way of getting the first level numbered paragraph numbers?  You'll see in my test document there are just 7 numbered paragraphs.
      #include <Word.au3> #include <Array.au3> Local $oWord = _Word_Create() Local $sDocument = @MyDocumentsDir & "\test.docx" Local $oDoc = _Word_DocOpen($oWord, $sDocument, Default, Default, True) $oRange = $oDoc.Range $sText = $oRange.Text $aLines = StringSplit($sText, @CR) _ArrayDisplay($aLines) $wdPropertyParas = 24 $sParas = $oDoc.BuiltInDocumentProperties($wdPropertyParas).Value $sParas = $sParas ConsoleWrite($sParas & @CRLF)  
      test.docx
    • By FrancescoDiMuro
      Good morning everyone
      I was talking about this UDF in this thread, but for not confusing "arguments", I opened a new thread...
      So, the issue I'm having, is the format of the table, that you can see in the image above... Can you help me out please? Thanks  
      Text of the previous post:
       
      Local $oWord = _Word_Create(False)             If @error Then                 MsgBox($MB_ICONERROR, "Errore!", "Errore durante la creazione dell'oggetto Word." & @CRLF & "Errore: " & @error)             Else                 ; The field alreay exists, but would be nice if I can create it... I thought at _FileCreate() :)                 Local $oDoc = _Word_DocOpen($oWord, $sCartellaModelli & "\Esportazione_Modello.doc")                 If @error Then                     MsgBox($MB_ICONERROR, "Errore!", "Errore durante l'aggiunta di un nuovo documento Word." & "Errore: " & @error)                 Else                     Local $oRange = _Word_DocRangeSet($oWord, 0)                     If @error Then                         MsgBox($MB_ICONERROR, "Errore!", "Errore durante il settaggio del range nel documento Word." & @CRLF & "Errore: " & @error)                     Else                         _Word_DocTableWrite($oRange, $aListView, Default)                         If @error Then                             MsgBox($MB_ICONERROR, "Errore!", "Errore durante la creazione della tabella." & @CRLF & "Errore: " & @error & "Informazioni: " & @extended)                         Else                             _Word_DocSaveAs($oDoc, $sCartellaEsportazioni & "\Esportazione_di_prova.doc")                         EndIf                     EndIf                 EndIf             EndIf And this is the actual result:

    • By Shane0000
      a Shift + Enter line break for Word 2007. is chr(11)
      #include <word.au3> $sText = 'Test' & @LF & 'Test' & @CR & 'Test' & @CRLF & 'test' & chr(10) & 'test' & chr(13) & 'test' $oWord = _Word_Create() $oDoc = _Word_DocAdd($oWord) $oRange = $oDoc.Range $oRange.InsertAfter ($sText) $iEnd = $oRange.End _Word_DocSaveAs($oDoc,'c:\test.doc') hehe dancing all around chr(11)
×
×
  • Create New...