Problem: Word sometimes doesn't choose "Single File Web Page" format automatically for .mht files.
Description:
When opening files in Word application there is an option to select file conversion format:
For the .mht files to be correctly decoded/viewed i noticed that selecting format "Single File Web Page" works perfect.
Is it possible to achieve this programmatically? Lets say I would like to open the .mht file in word application, and use word's converter to treat it as a "Single File Web Page" file.
So far I have found that Documents.Open method (https://learn.microsoft.com/en-us/office/vba/api/word.documents.open) accepts parameter "Format". But it seem like it doesn't have the format I need. The closest I see is wdOpenFormatWebPages(7), but it is not the same as "Single File Web Page"
https://learn.microsoft.com/en-us/office/vba/api/word.wdopenformat
VB:
Documents.Open FileName:="C:\test.mht", format:=7
C#:
Application app = new Application();
Document document = app.Documents.Open(FileName: #"C:\test.mht", Format: 7);
Good day community,
Microsoft support have already document this .mht issue and offer a simple solution. I use it to get quick 'highly detail QA and training document in Word format' from PSR.exe recording (also provide in all Windows terminal since Win7). I have a conversion script to do it in batch for my tester/trainer at my compagny. With the right title and the command 'dir /b', it also build a table of content to help research for newly employés :
Ref : https://support.microsoft.com/en-us/topic/the-confirmconversions-property-in-macro-changes-the-confirm-conversion-at-open-option-in-word-6f16c1db-4cb8-2727-dc4f-fdf6ef112ff5
Sub MyDocumentOpenMacro()
Dim x As Integer
' Set x equal to the current setting of the Confirm conversion at Open
' option before opening your file.
x = Application.Options.ConfirmConversions
' Open your file.
Documents.Open "C:\My Documents\Address.txt", ConfirmConversions:=False
' Use a conditional statement to set the Confirm conversion at Open
' option back to its setting (value of x) before opening your file.
If x = "0" Then
Application.Options.ConfirmConversions = False
Else
Application.Options.ConfirmConversions = True
End If
End Sub
Related
Currently I have a file name stored in string called filename. The file stored in the string is currently open. Issue is, this file could some times be opened in another instance of Visio.
I want to activate the file that is stored in filename string
My current method does not capture this - The code below only checks if the filename exists among the current/one instance of Visio.
For Each objDoc In objVisio.Documents
If objDoc.Name = filename Then
objDoc.activate
Exit for
End If
Next
How can I activate this file to bring it forward?
windows(filename & " - Microsoft Visio").activate
is not working either
I've tried
Dim objVisio as Visio.Application
Set objVisio = GetObject(filename).Application
which isn't working (maybe due to filename string only having the file name and not the entire file path as well)
Any other brute force methods available out there?
Any help is appreciated!
Try something like this:
objVisio.Application.Caption
Or
AppActivate "Microsoft Visio"
I guess another option is to look into this: https://msdn.microsoft.com/en-us/library/office/ff766749.aspx
I haven't worked extensively with Visio in VBA, so I am interested to see the true answer here.
I'm working on my first AppleScript (2.5) and can't seem to resolve my issue here.
I'm trying to open each markdown file in a folder and export to PDF. Opening the file with the specified application works, but I get 'The variable PDF is not defined' before the export happens.
I've tried four or five different sets of commands, from permutations on the save command to trying to use 'export' as some have suggested, but this form here appears to be the closest I've come to success. (Anytime I use export I get "Expected end of line, etc. but found identifier" and the word 'export' highlighted)
I appreciate any insight
tell application "Finder"
set sourceFolder to "Path:To:SourceFolder"
set MDFiles to files of folder sourceFolder whose name extension is "md"
end tell
repeat with f in MDFiles
set filePath to f as text
set newFilePath to (text 1 thru -2 of filePath) & "pdf"
tell application "MacDown"
open f
save f in file newFilePath as PDF
close f saving no
end tell
end repeat
After following #vadian's advice, it appears that the application does not have the ability to save to PDF.
I am trying to tie together a filemaker script that will export PDFs to a temporary space and use and apple script to print them.
I was able to cull together info from this and some other boards to create an applescript that will print the PDFs using Acrobat from a folder.
I have already created a script that finds the Related attachments and exports them to the desktop.
What I'm having trouble with is merging the two.
I need to export the PDF to a folder or temporary place and trigger the apple script to initiate the printing...
This great Suggestion was provided by Chuck of chivalrysoftware.com/…...
Calculate the location to export by appending the filename to Get( TemporaryPath ).
Export the container field contents to FileMaker to that path.
Save the path to a global field in FileMaker
Use an embedded AppleScript to access the global field path
Use AppleScript to open the file in Preview and print it
This is my apple script:
set myFolder to (path to desktop folder as text) & "Print:"
set myfiles to list folder myFolder without invisibles
repeat with myfile in myfiles
set mycurrentfile to ((myFolder as string) & (myfile as string)) as string
batchprint(mycurrentfile)
end repeat
on batchprint(mycurrentfile)
tell application "Adobe Acrobat Pro"
activate -- bring up acrobat
open alias mycurrentfile -- acrobat opens that new file
tell application "System Events"
tell process "Acrobat"
click menu item "Print..." of menu 1 of menu bar item "File"¬
of menu bar 1
click button "Print" of window "Print"
tell application "System Events"
tell process "Acrobat"
click menu item "Close" of menu 1 of menu bar item "File"¬
of menu bar 1
end tell
end tell
end tell
end tell
end tell
tell application "Finder" -- to move the printed file out
set x to ((path to desktop folder as text) & "Printed PDFs:")
if alias x exists then
beep
else
make new folder at the desktop with properties {name:"Printed PDFs"}
end if
move alias mycurrentfile to folder "Printed PDFs"
end tell
end batchprint
My Filemaker script is:
Go to Related Record[
Show only related records; From table: 'Attachments";
Using layout: "Attachements Report' (Attachments); New window
]
Enter Find Mode
Constrain Found Set [Restore]
Sort Records [Restore; No dialog]
# After finding the related attachments and constraining them to the specific type
# we rename and export them to the desktop
Go to Record/Request/Page [First]
Loop
Set Variable [$Path; Value:
Get ( DesktopPath ) & Attachments::Record number & "-"
& Attachment Type List 2::Prefix_z & Lien::Lien_ID_z1]
Export Field Contents [Attachments::file_c; $Path]
Go to Record/Request/Page [Next: Exit after last]
End Loop
Close Window [Current Window]
First of all, the FileMaker part. Create a global text field in one of your tables. It looks like the Attachments table would be the best place for it. I'll call it g_applescript_parameter for this.
Now we're going to use your $Path variable, which given the calc you've provided should be something like /Aslan/Users/chuck/Desktop/1234-ABC4321. I'd recommend appending a .pdf to the end of it since you'll be exporting PDF files. This may help later.
Also, I would recommend that you use Get( TemporaryPath ) instead of Get( DesktopPath ). Anything you place in the temporary folder will be automatically deleted when you quit FileMaker, which means you don't have to write anything to clean up the desktop folder later and you don't have to manually trash them either. Let FileMaker do that work for you. :)
Regardless, FileMaker uses a path of the form filemac:/volumeName/directoryName/fileName (see the notes in the Specify output file dialog box for the Export Field Contents script step). So you should also prepend filemac: to the beginning of your path variable.
All told, your $Path should be set to something like this:
"filemac:" & Get( DesktopPath ) & Attachments::Record number & "-" &
Attachment Type List 2::Prefix_z & Lien::Lien_ID_z1 & ".pdf"
So your export path for FileMaker should work better now. But AppleScript requires a different format for the path to the same file. Given the above, AppleScript's version should be something like /Users/chuck/Desktop/1234-ABC4321.pdf. In other words, everything after the drive name. Fortunately FileMaker can get the drive name with the Get( SystemDrive ) function. For me that function returns /Aslan/. So if we take the $Path variable as defined above and remove filemac: and the name of the drive as defined by Get( SystemDrive ) and add an extra slash at the beginning, that would convert our FileMaker path into an AppleScript path:
"/" & Substitute( $Path; "filemac:" & Get( SystemDrive ); "" )
Use Set Variable to create an $ASPath variable and set it to the above.
Now within your loop store the contents of the $ASPath variable within that global text field:
Loop
Set Variable[ $Path; …]
Set Variable[ $ASPath; …]
Set Field[Attachments::g_applescript_parameter; $ASPath)
Export Field Contents[Attachments::file_c; $Path]
Go to Record/Request/Page[Next; Exit after last]
End Loop
Now AppleScript can extract that information. I'm assuming that given an accurate file being passed to the batchprint function, batchprint will work, so keep that, but remove everything before it and use something like this:
set _pdf_path to contents of cell "g_applescript_parameter" of current layout
batchprint(_pdf_path)
on batchprint(mycurrentfile)
...
end batchprint
Add a Perform AppleScript step after the Export Field Contents step and place the above code in it.
Note that the first line of the above AppleScript will only work as written from within FileMaker. If you're testing this outside of FileMaker in, for example, Script Editor, then you'll need to make that first line read
tell applicaiton "FileMaker" to set _pdf_path ...
You don't need to do this within the Perform AppleScript script step because by default commands are sent to the enclosing FileMaker application.
I am using the following VB Script in a Word 2010 Doc saved as a Microsoft Word Macro-Enabled Template that is protected for form fields:
Sub SaveWithBkMarkedText()
'This code saves the Word file using the bookmark value for Maintenance Memo.
'The file is also saved to a folder in KnowHow for files related to this template.
Dim FileName As String
FileName = ActiveDocument.Bookmarks("mmn").Range.Text
'Use the C:\ code when saving the file locally
ActiveDocument.SaveAs "C:\Download\TemplatesFolders\" & FileName & ".doc"
MsgBox "Your Draft has been saved to KnowHow's Release Documentation site." & _
&vbCrLf & "The file name uses the MM that you included earlier: " & FileName, _
vbInformation + vbOKOnly, "Draft Saved to Minerva"
End Sub
The value entered into the Form Field for a FORMTEXT legacy-form object uses the Bookmark as the file name. Example, if the user enters 12345 as the value, the file is saved using this value as the filename: 12345.doc. This worked fine until a week ago when the filename is now being Prefixed with FORMTEXT 12345.doc. I have tried using this same VB script in older versions of Word on a different machine, and created from a NEW Template with the script added in from scratch, and the same issue is appearing on that machine as well. Prior to this, I was able to update my template with NO problem, but now I can't update this one FORMTEXT field without it affecting the whole file. I can update any other FORMTEXT in the template that does not use the Bookmark value as the file name, and it works. Also, I have tried changing the Bookmark Reference to another FORMTEXT object, as well as saving the file as a .DOCX and the same problem occurs regardless. What is causing the FORMTEXT to appear in the filename?
You have to un-protect the document (template) and then make the VBA programming. Once it is done, then you can protect it again (for filling forms) and you will not see the "FORMTEXT" in the filename when you run the macro.
Hope it helps.
To the OP, did you resolve this issue? I'm now having the same problem, I'm using form field text with bookmarks and using VB.net to get the bookmark.text which is now prefixed with FORMTEXT, just using a bookmark on it own and its OK, no prefix. I'm going to try and remove the first 9 characters from the result using code, a workaround, yes but it might work.
Know this is an old thread but ran into same issue. As a workaround...
Replace FORMTEXT with null "". In OP circumstance:
Dim FileName As String
FileName = ActiveDocument.Bookmarks("mmn").Range.Text
FileName = Replace(FileName, "FORMTEXT ", "")
Not a "fix" for the issue or elegant but it works.
Had the same issue. Simply delete current bookmark and add a new one. If that does not work than instead of using the following:
FileName = ActiveDocument.Bookmarks("mmn").Range.Text
try using:
Selection.GoTo What:=wdGoToBookmark, Name:="mmn"
Filename = Selection.Text
I want to save an OLE Excel Object (MS Excel 2000 format) within a Lotus Notes document to make it available to MAC and Browser Users. After I attached it to a new Notes document MS Excel 2010 does not open it correctly. The file itself seems to be somehow valid, as I can detach and preview it with IE or Windows Explorer or even with the Lotus Notes preview. Only MS Excel 2010 is somehow unable to display the Excel document.
Here my code to extract the OLE file to file system:
dirLN = s.GetEnvironmentString("Directory",True)
subdirLN = "\"
Select Case dokArt
Case "Excel"
anhangLN = "anhang.xlsx"
Case "PowerPoint"
anhangLN = "anhang.pptx"
Case "Word"
anhangLN = "anhang.docx"
Case Else
Exit function
End Select
Set rtitem = doc.GetFirstItem("Body")
For i = 0 To UBound(rtitem.EmbeddedObjects)
Set objDoc = rtitem.EmbeddedObjects(i)
dateiLN =dirLN+subdirLN+anhangLN
Set oHandle = objDoc.Activate(False)
Call oHandle.savecopyAs(dateiLN)
Next
and this is how I attach it back to a document
'Anhang anhängen
Set rtItem = New NotesRichTextItem(doc,"Body")
Call rtItem.Embedobject(1454, "", dateiName)
What can I do to save the Excel file in the correct format ? I tried several ways, but I could not find any alternative to the 'savecopyas' method within the handle.
I think you're saying after any kind of detachment, you can't open the document with Excel, in which case the comments already provided probably apply
But in case you mean it doens't open on the screen right away ..
The Notes help quotes re Activate method :
Activate :
Syntax
Set handleV = notesEmbeddedObject.Activate( show )
Parameters
show
Boolean. If True, the server application displays its user interface. If False, the server application hides its user interface.
If this is running on the user's client, the False in your Activate method is asking it not to display.