Trying to get the name of the active window with it's description, can't find any method.
My problem is that while I can access document's file name with Document.Name, I can't get the commentaries that Word attaches to it, like (Compatibility Mode, Last modified by User etc), without them, the method Windows(Document.Name) doesn't work, is there any solution for this?
My program opens four new documents and switches in a loop the active document, taking information from the original and putting some excerpts in the new ones.
Everything works when there is no commentaries for documents, but as they appear, program breaks, saying:
5941 The requested member of the collection does not exist
Thanks for reading!
This:
Windows(1).Document
will give you the document associated with a window. (You may need to loop through the windows to find the one you're interested in.)
Once you have the document you can access its properties:
Windows(1).Document.CompatibilityMode
Hope that helps
Related
I am trying to retrieve via VBA the last entry (or all entries) of the directories list shown in the Move menu of Outlook. This menu is normally visible in the Home taskbar. The objective is thereafter to re-use this directory for instance to "change focus window to the last used folder" (from this list).
I have checked in the Microsoft documentation but could not find it, though I might have missed it.
I also didn't find it in the OlDefaultFolders list, which is logical since it's not a folder in the tree view anyway, but only a list of recently used folders.
I did look into this thread but the objective of the question author seems a bit different as there is no question of the Move menu: Get the folder where the last mailitem was moved in Outlook?
Did anyone had the same issue or find a way to circumvent this problem?
Maybe to store the last used folder elsewhere each and every time an email is moved... a bit overkill but that could work I guess.
Thanks in advance for your help!
Is there a way to get some sort of collection of "paragraphs, images, headings1, headings2" and other "word elements" with a VBA function call. I was looking into this, I ran accros ActiveDocument.fields, but it doesn't seem to be it.
What I need to do is copy these elements, one by one, into an excel document, but I do not know how to access them in the first place. Is there any collection or what would be the syntax for accessing these. My idea is to make a loop and use it there, I could be going about this wrong.
In Word:
Hit Alt+F11 to get the VB editor.
Hit F2 to get the Object Browser.
Type "Document" into the search box and hit Enter.
Click on the row that says "Word" under Library and "Document" under Class.
In the "Members of 'Document'" list you will see all sorts of goodies! That includes things like Document.Paragraphs :) . You can then search on MSDN for details of how to use the listed fields. Prepare for lots of searching and reading online!
Once you have found the fields you are interested in, you will be able to try some things. Once you have code that almost works, but not quite, you will be ready to post detailed questions here asking for further help. See the SO tour for more on that process.
I have VBA that, in Word 2010, will default a file name into the Save As screen when the user selects the Save As file option. Word 2016 (Office 365) has a different interface with a screen to select a save location (OneDrive, This PC,etc) prior to the "standard" Save As dialog box appearing which seems to have broken the code to generate a specified default file name.
The code (with title simplified) is
Sub FileSaveAs()
With Dialogs(wdDialogFileSaveAs)
.Name = "MyTitle"
.Show
End With
End Sub
If I run the code in Developer to Debug, it works fine, with the Save As screen appearing and the file name defaulting but it does not work in the live environment where the file name defaults to the previous document name.
Based on web research, I have tried additional code to change the properties of the document place the name in the title as this is supposed to then default when Save As is selected but that also doesn't work.
Any suggestions or recommendations on how to resolve this would be appreciated.
Thanks!
Update 1/11/16:
Have been able to get a little closer by using the following:
Application.DocumentBeforeSave Event
example here https://msdn.microsoft.com/en-us/library/office/ff838299.aspx
tied to Using Events with Application Object
example here https://msdn.microsoft.com/en-us/library/office/ff821218.aspx
Had to add
Cancel=True
to the end of the event procedure code or the Save as Dialog box will open twice.
Still a bit clunky and seems to be limited to run only before the first user generated save event but almost workable.
Wanted to share what I found in case it helps others but any other suggestions for improvement would be appreciated as it still doesn't seem like the best solution.
Thanks again!
Thanks for reporting this. I have a potential workaround that I hope will help.
Could you use the SendKeys method (https://msdn.microsoft.com/en-us/library/office/gg278655.aspx) to send the keyboard shortcut (F12 for the Save As dialog, full list: http://aka.ms/Tf6yv0) to the application e.g.
App.SendKeys("{F12}")
when you need the Save As dialog to be displayed?
I hope this helps. Thanks again for bringing this issue to our attention, we will be looking further into the root cause.
Every day our Helpdesk has to send out a report. That report needs to link to a website that displays that days statistics.
Example URL:
http://hostname/dashboardname/date
Which would look like this:
http://hostname/HelpdeskTickets/2015-03-18
Heres what I've tried:
First I looked into field code values and doing something like this
{HYPERLINK "http://hostname/HelpdeskTickets/{DATE \# "yyyy-MM-dd"}"}
And this works, until you close the outlook message. If you don't have F9 to update the field code, and save and close the .msg file it will disappear leaving just the blank link without a date. If you hit F9 before closing it, it puts that days date into the field, however when you close and save it the field code disappears and leaves the date in place of the date field code. Also I noticed this problem doesn't happen in word. You can save and close a word file and it keeps the field codes.
Another thing I've tried is to use VBA to edit the links in the message body. So far nothing has actually worked.
The only thing that partially worked was taking the body of the document and using a string replace function on it. However this destroys all formatting and hyperlinks along with it.
I'm open to any ideas on how this can be achieved.
My main problem is that the people at the helpdesk can't seem to use anything that isn't fool proof. So having them press F9 before sending this email was actually scaring people that they wouldn't be able to do that.
You can use VBA to edit the message body programmatically. It is not clear what code you used earlier, but the main ways are described below:
HTMLBody - a string representing the HTML body of the specified item. The HTMLBody property should be an HTML syntax string.
The Word editor. The WordEditor property of the Inspector class returns an instance of the Document class from the Word object model. So, the message body is represented by the Word Document.
You can read more about all possible ways in the Chapter 17: Working with Item Bodies.
We are trying to save some additional information with a document using the QuerySaveDocument event. However it seems that it is not being triggered at all.
<xp:executeScript script="#{javascript:setField(document1, 'cCustAddr1_fi', 'test');}">
</xp:executeScript>
This is our basic script. All the setField() method does is use replaceItemValue to try and set the field. However it seems that QuerySaveDocument is not even being triggered since we can write pretty much anything and the document will still save without problem, even if it would be impossible to execute.
We have also tried using a simple document1.getDocument().replaceItemValue() script, but again I dont think it even attempts to execute. Our documents save perfectly fine too,
Do you see any reason for this, are we doing our saving wrong, or should we be attaching data onto the document in another way?
Thanks.
Your other question on Unplugged (Using other dialog controls in iOS) suggests that you are using the Unplugged Mobile Controls project.
If that is correct then my comment above applies - the querySaveDocument event won't get fired . You can look at the code in UnpSaveDocument.xsp and possibly add your own SSJS code to that.
Alternatively, if you want an additional item created on your back-end Notes document then you should just be able to add a hidden field to the UnpFormEditor that is bound to the document1 data source and using the relevant item name you want.