When I tried to delete Document 1's headers.
tell application "Microsoft Word"
set headers to get story range document 1 story type primary header story
delete headers
end tell
I got a problem "Microsoft Word got an error: Can’t get document "Document1"." number -1728 from document "Document1"
Why?
I open a document, and set a header.So the document 1 exist.When I tried this code.
tell application "Microsoft Word"
set headers to get story range document 1 story type primary header story
get content of headers
end tell
It's all right.And get the header's text content.
I think, you should avoid creating variable headers, which is reserved word (property). Test following snippet yourself, because I don't use Microsoft Word at all.
tell application "Microsoft Word"
tell (story range document 1 story type primary header story)
delete its headers
end tell
end tell
Related
I'm retrieving paragraph stylenames from openXML and using paraID property to get the right one.
During testing i noticed that depending on the word document the attribute might not be present on any of the paragraphs.
I do know that this is a internal runtime paragraph id for Word.
So the question is: What generates the paraId properties on the paragraphs, can't seem to figure this out.
ps. I don't want to use get_style() since that is waay too slooooow...
edit: added code example
This is in some documents "0" and in some documents a valid hex id
string sParaId = range.Paragraphs.First.ParaID.ToString("x").ToUpper();
This open xml document sometimes have valid w14:paraId-attribute and sometimes it is missing:
activeDocument = Globals.ThisAddIn.Application.ActiveDocument;
wordXML = XElement.Parse(activeDocument.WordOpenXML);
... I would like to get the styleName something like this from the WordOpenXML but for now it seems i might go for some other option since I don't know when paraId is added in the XML.
paraEl = ooXMLElementList.Descendants().Where(x => x.Name.LocalName ==
"p").FirstOrDefault(x => x.Attribute(w14 + "paraId")?.Value == sParaId);
styleName = paraEl.Descendants().FirstOrDefault(x => x.Name.LocalName ==
"pStyle") != null ? paraEl.Descendants().FirstOrDefault(x =>
x.Name.LocalName == "pStyle").Attribute(w + "val").Value : "Normal";
From the Word Language Reference for Paragraph.ID:
Returns or sets the identifying label for the specified object when
the current document is saved as a Web page.
Since the document is not saved as HTML the property has no meaning.
The ParaId property is not exposed for developers to use. It's not visible in the VBA object model, but due to the way the PIA (primary interop assemblies) are generated the .NET developer will see it. From the language reference:
Reserved for internal use.
Not sure what it is you're really trying to do, but you can use Word's Range.Find capability to search formatting (styles).
I am writing an applescript which works as an email merge that takes information from a Numbers document (name, email address, license codes, promo codes) and generates an email in Mail. After inserting the base & dynamic content, some text formatting occurs (making text bold and red or blue). The code works, but the message signature disappears once some of the content is edited. The signature is there but it disappears seconds later.
However, if I set a breakpoint (using Script Debugger) on the line the message signature is set, it works just fine. Below is a sample code which illustrates the point:
tell application "Mail"
set theMsg to (make new outgoing message with properties {subject:"Test", content:"Wahoo", visible:false})
tell theMsg
make new to recipient with properties {name:"Josh Booth", address:"none#none.com"}
set character 1 to "Y"
set color of character 1 to {60000, 1, 1}
end tell
set theMsg's message signature to signature "JB_SocialMedia"
log "Fin"
end tell
Additionally, even though the property visible is set to false, it shows up anyway. Running on OS X Yosemite, but this issue has also happened in Mavericks.
Any thoughts?
Create the signature with the message.
tell application "Mail"
set theMsg to (make new outgoing message with properties {subject:"Test", content:"Wahoo", visible:false, message signature:signature "JB_SocialMedia"})
tell theMsg
make new to recipient with properties {name:"Josh Booth", address:"none#none.com"}
set character 1 to "Y"
set color of character 1 to {60000, 1, 1}
end tell
log "Fin"
end tell
Searched around a bit and could not find an existing post with my exact question.
I am creating an Access (2003) database utilizing multiple forms and tables that need to communicate and share information with one another (i.e. - first/last name, etc.). The main form/table, "Personnel", will hold a majority of the information, yet the other forms/tables will only hold information pertinent to certain situations/circumstances, so not every entry in "Personnel" will have a concurrent entry in "Hired", for example. If a record with the same name already exists, I would like a MsgBox to tell me so and open that entry (in the form, for editing), if not a new entry would be created, auto-populated with pre-selected fields (i.e. - first/last name).
After an option is selected from a pull-down menu, the appropriate form is accessed/opened, "Hired", for example (This part works).
The copying information across forms does not work.
Dim rstPers, rstHired As DAO.recordset
Dim LastName As String
If status = "hired" Then
DoCmd.OpenForm "Hired Information"
Set rstPers Forms!Personnel.RecordsetClone
Set rstHired Forms![Hired Information].RecordsetClone
????
...
End If
I have tried to do this multiple ways but nothing seems to work. Nothing populates in the new Form or table. Am I looking at it the wrong way? Should I try a different approach?
Hope my explanation makes sense. Thanks for any help.
-Charles
You have a bad approach indeed.
Your forms are linked to a table. So you should avoid as much as possible to manipulate or retrieve a form's data directly using a recordsetclone, instead try to retrieve this data directly from the table.
So if you want to open your "hired information" form:
Dim RS As Recordset
Dim IDperson As String
IDperson = me.ID ' or whatever
Set RS = CurrentDb.OpenRecordset("SELECT ID FROM TableHired WHERE ID='" & IDperson & "'")
If RS.BOF Then
' No record exist - Open form in record creation
DoCmd.OpenForm "FormHired", acNormal, , , acFormAdd
Else
' record exists, open form and position it oon the record's ID
DoCmd.OpenForm "FormHired", acNormal, , "ID='" & RS!ID & "'", acFormEdit
End If
Of course it won't work like this as you didn't provide enough info.
Review this code and adapt it with your fields name (IDs), table name (TableHired) and FormName (FormHired) and following the situation on where and how you will trigger it. Also if your ID is not a string, you should remove the quotes in the SQL
I am trying to organize the revisions in a Word document. I am obviously missing something pretty basic, as I can't get very far.
The following script
tell application "Microsoft Word"
set activeDoc to active document
set revCount to count of revisions of activeDoc
set aRev to first item of revisions of activeDoc
set auth to author of aRev
set when to date value of aRev
end tell
generates the following:
tell application "Microsoft Word"
get active document
--> active document
count every revision of active document
--> 1275
get item 1 of every revision of active document
--> current application
Result:
error "The variable aRev is not defined." number -2753 from "aRev"
The error occurs on the "set auth" reference. I have tried various items in the list with the same result. I also noticed from the dictionary that text ranges can contain revisions, but even with a range spanning the entire document I get zero from a count of revisions from it.
Either of the following should fix the immediate problem:
set aRev to first revision of activeDoc
or
set theRevs to the revisions of activeDoc
set aRev to the first item of theRevs
(I thought that the following should work, but right now I have forgotten why not)
set aRev to the first item of (revisions of activeDoc)
I need to add a few fields to a Word 2010 DOTX template which are to be populated automatically with custom content at "run time" when the document is opened in a C# program using Word Interop services. I don't see any way to assign a unique name to "Ask" or "Fill-In" fields when adding them to the template via the QuickParts ribbon-menu option.
When I iterate the document.Fields collection in the C# program, I must know which field I'm referencing, so it can be assigned the correct value.
It seems things have changed between previous versions of Word and Word 2010. So, if you answer please make sure your answer applies to 2010. Don't assume that what used to work in previous versions works in 2010. Much appreciated, since I rarely work with Word and feel like a dolt when trying to figure out the ribbon menuing in 2010.
You are correct in that fields don't necessarily have a built-in way to uniquely distinguish themselves from other field instances (other than its index in the Fields collection). However, you can use the Field.Type property to test for wdFieldAsk or wdFieldFillIn . If this is not narrow enough to ID then you will need to parse your own unique identifier from the Field.Code. For example, you can construct your FILLIN field as:
{ FILLIN "Hello, World!" MYIDENTIFER }
when you iterate through your document.Fields collection just have a test for the identifier being in the string. EDIT: example:
For Each fld In ActiveDocument.Fields
If InStr("CARMODEL", fld.Code) <> 0 Then
''this is the carmodel field
End If
Next
Another alternative - seek your specific field with a Find.Text for "^d MYIDENTIFIER" (where ^d is expression for 'field code')
Let me know if this helps and expand on your question if any gaps.