Windows 10 Word 365 File Name Time Stamp Automation w/o VBA


  1. Posts : 19
    Windows 10
       #1

    Windows 10 Word 365 File Name Time Stamp Automation w/o VBA


    Word Field-Code IF statement execute (w/oVBA) before SaveAs Dialog. Field-Code Example: " If {REF DocProperty Title <> "" ...} " - Microsoft Q&A
    Word Field-Code IF statement execute (w/oVBA) before SaveAs Dialog. Field-Code Example: " If {REF DocProperty Title <> "" ...} "


    Windows 10 Word 365 File Name Time Stamp Automation w/o VBA-word-file-name-automation.png

    This is achieved by Field-Code formula in 1st Paragraph (White Font). Word Save As will reflect this if Title is blank.....

    Thanks to dougrobbinsmvp@gmail.com for great support!
    Details in .
    https://answers.microsoft.com/en-us/...e-b9eab8e24213

    - - - Updated - - -

    Word 365 File Name Time Stamp Automation w/o VBA. I use Field-Code formula in 1st Paragraph (White Font). Word Save As but Correct Name only appears on 2nd SaveAs.
    Details .
    Word 365 Conditional Text to depend on Document Title. How? - Microsoft Community
    Windows 10 Word 365 File Name Time Stamp Automation w/o VBA - Windows 10 Forums
    Assuming reason (I'm unaware of) NOT to update other field before Print, I need IF statement execute before SaveAs Dialog. Example: " If {REF DocProperty Title <> "" ...} "

    Please help vote to get Microsoft implement IF statement to execute before SaveAs Dialog (IF condition for Document Properties)

    - - - Updated - - -

    A suggested file name (in the Save As dialog box) will start at with the first character in the first text paragraph and end with the character prior to the first punctuation mark, as you have noticed.
    If there is a Web site that defines paragraph, I much appreciate info because Links (i/c in my first post) quotes:
    "anything with a hard return after it (you have pressed Enter or Return)"
    leading me misunderstanding punctuation as part of paragraph. If you think otherwise, I also appreciate how you interpret above quote.
    Going forward, should I suggest to: ⒈ Microsoft s.t. paragraph include punctuations ? ⒉above free support Website to redefine paragraph? (s.t. other Words users not to repeat my mistake?)
    https://answers.microsoft.com/en-us/...d-8af59f37aef8
    - - - Updated - - -

    While still aiming program-free solution, is there more info why period/comma results in truncated Name ? ;

    File-SaveAs-Dialog-Box currently shows "0.docx" when 1st paragraph is "0,Cover 2021 08.pdf¶" ?

    Comma is not in list of reserved characters;

    Period may be problematic b/c it separate base file name from extension but not in Reserve list

    Quote Naming Files, Paths, and Namespaces - Win32 apps | Microsoft Docs of Use of Period and Reserved Characters :

    "

    Use a period to separate the base file name from the extension in the name of a directory or file.

    Use any character in the current code page for a name, including Unicode characters and characters in the extended character set (128–255), except for the following:

    The following reserved characters:

    < (less than)

    > (greater than)

    : (colon)

    " (double quote)

    / (forward slash)

    \ (backslash)

    | (vertical bar or pipe)

    ? (question mark)

    * (asterisk)

    Integer value zero, sometimes referred to as the ASCII NUL character."

    - - - Updated - - -

    Ideally, my 2cent alternative (least disruption of code pertinent to name-output of FileSaveAs DialogBox) is to use variant of period:

    Period Variant U+2024 ONE DOT LEADER ․

    Example of 1st paragraph "0․Cover 2021 08.pdf¶" which is almost identical to human eye "0.Cover 2021 08.pdf"

    Leader (typography) - WikipediaLeader (typography) - Wikipedia

    But this requires Microsoft involvement which is beyond my control....

    - - - Updated - - -

    Since Microsoft Office should have Unified User Experience, since PowerPoint 365 show "0․Cover 2021 08.pdf¶" in SaveAs DialogBox, IMHO, Word should match PowerPoint?

    Period Variant U+2024 ONE DOT LEADER ․
    Example of 1st paragraph "0․Cover 2021 08.pdf¶" which is almost identical to human eye "0.Cover 2021 08.pdf"

    Leader (typography) - WikipediaLeader (typography) - Wikipedia
    But this requires Microsoft involvement which is beyond my control..

    - - - Updated - - -

    Word 365 Formula How to extract text from Template File Name (constructed Excel-Formula-Style) ? until Microsoft updates for sake of Unified User Experience

    As part of Default File Name automation (w/o VBA) for Word 365, I am working around limitation of special characters . PowerPoint do not share this limitation.
    Since Microsoft should have Unified User Experience, I expect this limitation to be temporary.
    If Word 365 accept special characters, my first paragraph will be "0.Cover 2021 06" which PowerPoint is capable of (using Period Variant U+2024 ONE DOT LEADER ․
    "0․Cover 2021 06.pdf¶" which is almost identical to human eye "0.Cover 2021 06.pdf")
    Before this happens, my first paragraph will be "0句號Cover 2021 06" to be extracted from Template-File-Name.
    When Word accept special characters, all End-User need to do is change Template-File-Name to "tool.Redbook.CoverPage.Text(0.Cover 2021 06).dotx".
    This frees End-User from changing formula to get FileSaveAsDialogBox to show "0.Cover 2021 06" when Word improves. He/She only needs to change Template File Name to "tool.Redbook.CoverPage.Text(0.Cover 2021 06).dotx"
    How to get "0句號Cover 2021 06" from "tool.Redbook.CoverPage.Text(0句號Cover 2021 06).dotx" which is Template-File-Name ?
    Word 365 Default File Name using First paragraph - character - Microsoft Community

    - - - Updated - - -

    I came up with what is perceived as not-so-much-programming solution as follows.
    This is Powershell which is considered more script than programming.
    I am still thinking Microsoft to Unify Word to match PowerPoint which is more tolerant of special characters.

    Following code remove need to open template but not yet fully automated;
    Need User to
    ⒈ run Script ⒉Paste Filename from Clipboard ⒊Select PDF printout location

    Bug found so far: remove some redundant SendKeys lines which resulted in Template Name showing up...
    Code:
    <#
    https://gregcaporale.wordpress.com/2012/01/18/powershell-to-print-files-automatically/
    $folder = ‘c:\DocsToPrint’
    $filter = ‘*.pdf’
    $fsw = New-Object IO.FileSystemWatcher $folder, $filter -Property @{IncludeSubdirectories = $false;NotifyFilter = [IO.NotifyFilters]’FileName, LastWrite’}
    Register-ObjectEvent $fsw Created -SourceIdentifier FileCreated -Action {
    $name = $Event.SourceEventArgs.Name
    Start-Process -FilePath (Join-Path “C:\DocsToPrint” $name) -Verb Print -PassThru | %{ sleep 10;$_ } | kill
    }
    #>
    
    <#
    Tool Redbook Cover Page 
    Print To PDF 
    Filename (from 1st Paragraph of Template) will be pasted into Clipboard
    End-User needs to 
    ⒈ paste FileName from Clipboard when Dialog Box Shows for PDF file location
    ⒉ Select Folder for PDF file
    ⒊ Press Enter
    #>
    
    
    <#
    https://stackoverflow.com/questions/65760455/how-to-automate-print-to-pdf-with-windows-powershell
    #>
    
    Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
    
    ### Start of script (store list of existing variable names)
    $ExistingVariables = Get-Variable | Select-Object -ExpandProperty Name
    
    $mypath = $MyInvocation.MyCommand.Path
    Write-Output "Path of the script : $mypath"
    $mypathonly = Split-Path $mypath -Parent
    Write-Output "Path of the script : $mypathonly"
    $ScriptName = $MyInvocation.MyCommand.Name
    Write-Output "`nName of the script : $scriptname"
    
    function ConvertTo-PDF {
    	param(
    		$TextDocumentPath
    	)
    #https://social.technet.microsoft.com/Forums/office/en-US/04ddfe8c-a07f-4d9b-afd6-04b147f59e28/automating-printing-to-pdf	
    	Add-Type -AssemblyName System.Drawing
    	$doc = New-Object System.Drawing.Printing.PrintDocument
    	$doc.DocumentName = $TextDocumentPath
    	$doc.PrinterSettings = new-Object System.Drawing.Printing.PrinterSettings
    	$doc.PrinterSettings.PrinterName = 'Microsoft Print to PDF'
    	$doc.PrinterSettings.PrintToFile = $true
    	$file=[io.fileinfo]$TextDocumentPath
    	$pdf= [io.path]::Combine($file.DirectoryName, $file.BaseName) + '.pdf'
    	$doc.PrinterSettings.PrintFileName = $pdf
    	$doc.Print()
    	$doc.Dispose()
    }
    
    Function Printto-PDF ($filepath, $PrintToFileName) {
    #https://stackoverflow.com/questions/65760455/how-to-automate-print-to-pdf-with-windows-powershell
           $VerbosePreference = "Continue"
           add-type -AssemblyName microsoft.VisualBasic
           add-type -AssemblyName System.Windows.Forms
    
                         [System.Windows.Forms.SendKeys]::SendWait($PrintToFileName)
           start-sleep -Milliseconds 2500
                  [System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
           start-sleep -Milliseconds 1500
    
           $focus = 2000
           $FilePath = Get-Item $Filepath
           $newfile = $Filepath.basename + '.pdf'
           $PrtProcess = Start-Process $Filepath.fullname -verb Print 
            $PrtProcessToPrinter = $PrtProcess | out-printer -name "Microsoft print to PDF"  
           start-sleep -Milliseconds $focus
           [System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
           start-sleep -Milliseconds 250
           [System.Windows.Forms.SendKeys]::SendWait($newfile)
           start-sleep -Milliseconds 250
           [System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
           start-sleep -Milliseconds 1500
    <#       
    start-sleep -Milliseconds 1500
                  [System.Windows.Forms.SendKeys]::SendWait($PrintToFileName)
           start-sleep -Milliseconds 2500
                  [System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
           start-sleep -Milliseconds 1500
           #>
    
    }
    $PrintFilePath = "T:\RedBook\0. Cover YYYY MM⁻¹.Distribution List.dotx"
    $PrintToFileName = "Test.pdf"
    
    $filename = $PrintFilePath
    $wd = New-Object -ComObject Word.Application
    $wd.Visible = $false
    $doc = $wd.Documents.Open($filename)
    $FirstParagraph = $doc.Paragraphs[1].range.Text
    $doc.close
    $wd.Quit()
    Write-Host $FirstParagraph
    
    
    $PrintToFileName = $FirstParagraph
    
    #https://adamtheautomator.com/powershell-copy-to-clipboard/
    Write-Output $PrintToFileName | Set-Clipboard
    
    # ConvertTo-PDF $PrintFilePath
     Printto-PDF $PrintFilePath
    
    ### End of script (remove new variables)
    $NewVariables = Get-Variable | Select-Object -ExpandProperty Name | Where-Object {$ExistingVariables -notcontains $_ -and $_ -ne "ExistingVariables"}
    if ($NewVariables)
        {
        Write-Host "Removing the following variables:`n`n$NewVariables"
        Remove-Variable $NewVariables
        }
    else
        {
        Write-Host "No new variables to remove!"
        }
    Last edited by sunny123; 24 Aug 2021 at 22:09. Reason: suggest to Microsoft
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 22:17.
Find Us




Windows 10 Forums