powershell edit powerpoint slide notes - powershell

I am trying to use PowerShell to pro-grammatically update notes in PowerPoint slide notes. Being able to do this will save tremendous amounts of time. The code below allows me to edit the notes field with PowerShell but it messes up the format each time.
$PowerpointFile = "C:\Users\username\Documents\test.pptx"
$Powerpoint = New-Object -ComObject powerpoint.application
$ppt = $Powerpoint.presentations.open($PowerpointFile, 2, $True, $False)
foreach($slide in $ppt.slides){
if($slide.NotesPage.Shapes[2].TextFrame.TextRange.Text -match "string"){
$slide.NotesPage.Shapes[2].TextFrame.TextRange.Text = $slide.NotesPage.Shapes[2].TextFrame.TextRange.Text -replace "string","stringreplaced"
}
}
Sleep -Seconds 3
$ppt.Save()
$Powerpoint.Quit()
For example, right now it will iterate through each slide's notes and update the word string to stringreplaced but then the entire notes text becomes bold. In my notes I have a single word at the top of the notes that is bold and then text below it. For example, a note on a slide my look like this:
Note Title
Help me with this string.
After PowerShell updates the notes field it saves it to a new .pptx file but the note now looks like this:
Note Title
Help me with this stringreplaced.
Any ideas on how to update slide notes without messing up any formatting found in the notes? It only messes up formatting for slides the script updates.

When you change the entire text content of a textrange in PPT, as your code's doing, the changed textrange will pick up the formatting of the first character in the range. I'm not sure how you'd do this in PowerShell, but here's an example in PPT VBA that demonstrates the same problem and shows how to use PPT's own Replace method instead to solve the problem:
Sub ExampleTextReplace()
' Assumes two shapes with text on Slide 1 of the current presentation
' Each has the text "This is some sample text"
' The first character of each is bolded
' Demonstrates the difference between different methods of replacing text
' within a string
Dim oSh As Shape
' First shape: change the text
Set oSh = ActivePresentation.Slides(1).Shapes(1)
With oSh.TextFrame.TextRange
.Text = Replace(.Text, "sample text", "example text")
End With
' Result: the entire text string is bolded
' Second shape: Use PowerPoint's Replace method instead
Set oSh = ActivePresentation.Slides(1).Shapes(2)
With oSh.TextFrame.TextRange
.Replace "sample text", "example text"
End With
' Result: only the first character of the text is bolded
' as it was originally
End Sub

Related

Change Alt Text for Multiple Form Control Checkboxes

Is there a way to update the alt text for multiple form control checkboxes at once using Excel VBA? I have about 20 check boxes on a worksheet {"Sheet1"} (Check Box 1, Check Box 2, ... Check Box 20) and need to change the text for all to = "In Progress". Thanks in advance!
"Finding and Replacing in Text Boxes
by Allen Wyatt
(last updated July 20, 2019)
Sub TextBoxReplace()
Dim shp As Shape
Dim sOld As String
Dim sNew As String
'Change as desired
sOld = "Old string"
sNew = "New string"
On Error Resume Next
For Each shp In ActiveSheet.Shapes
With shp.TextFrame.Characters
.Text = Application.WorksheetFunction.Substitute( _
.Text, sOld, sNew)
End With
Next
End Sub
This macro steps through all the shapes in the worksheet (text boxes are shapes) and then replaces whatever is in the sOld variable with whatever is in the sNew variable."
From excelribbon.tips.net
Disregard; I found a solution! ^_^
https://excelribbon.tips.net/T009264_Finding_and_Replacing_in_Text_Boxes.html

I need to place the text near by their figure/table citation. My actual text placed at end of document. How to achieve using perl?

%%Figure-9
\begin{figure}[t]
\figurebox{}{}{1}[fgene-10-00561-g009]
\caption{Ectopic expression of \textit{TaPP2C135} in
\textit{Arabidopsis}. \textbf{(A)}~Expression levels of}
\end{figure}
Need to place the above figure text near to citation end of paragraph, Citation would be in text ".... (\hyperref[F9]{\textbf{Figure~9}})."
Kindly help genius, i am the beginner!
In tex file we couldn't find the end paragraph with a simple logic. Hence I have placed the figure at the end of the figure citation.
use strict;
use warnings;
my $texcontent = ' Sample content...
Need to place the above figure text near to citation end of paragraph, Citation would be in text ".... (\hyperref[F9]{\textbf{Figure~1}})."
Need to place the above figure text near to citation end of paragraph, Citation would be in text ".... (\hyperref[F9]{\textbf{Figure~2}})."
Need to place the above figure text near to citation end of paragraph, Citation would be in text ".... (\hyperref[F9]{\textbf{Figure~9}})."
Need to place the above figure text near to citation end of paragraph, Citation would be in text ".... (\hyperref[F9]{\textbf{Figure~3}})."
%%Figure-1
\begin{figure}[t]
\figurebox{}{}{1}[fgene-10-00561-g009]
\caption{Ectopic expression of \textit{TaPP2C135} in
\textit{Arabidopsis}. \textbf{(A)}~Expression levels of}
\end{figure}
%%Figure-2
\begin{figure}[t]
\figurebox{}{}{1}[fgene-10-00561-g009]
\caption{Ectopic expression of \textit{TaPP2C135} in
\textit{Arabidopsis}. \textbf{(A)}~Expression levels of}
\end{figure}
%%Figure-3
\begin{figure}[t]
\figurebox{}{}{1}[fgene-10-00561-g009]
\caption{Ectopic expression of \textit{TaPP2C135} in
\textit{Arabidopsis}. \textbf{(A)}~Expression levels of}
\end{figure}
';
my ($pre,$match,$post) = "";
while($texcontent=~m/\%\%(Figure\-(?:[\w]+))\n?\\begin\{(figure\*?)\}((?:(?!\\end\{\2\}).)*)\\end\{\2\}/gs)
{
$pre = $pre.$`; $match = $&; $post = $'; (my $figId = $1)=~s/\-/\~/i; #%%Figure-1 replaced with Figure~1
if($pre=~m/$figId\}\}\)/i) #Searching the ID
{
$match=~s/\{figure/\{completedfigure/i; #Completed the figures changed to completedfigures.
$pre=~s/$figId\}\}\)/$&\n<figplacedhere>$match<figplacedhere>/i; #TAG Placed figures identification
$match = "";
}
$pre = $pre.$match; $texcontent = $post;
}
if(length $pre) { $texcontent = $pre.$post; }
$texcontent=~s/<figplacedhere>//g; $texcontent=~s/\{completedfigure/\{figure/g;
print "--\n$texcontent\n--\n";
Purely based on your input I have updated the code unless until the sample input differs might be the code doesn't work.

Finding text AND fields with variable content in Word

I need to find and delete every occurrence of the following pattern in a Word 2010 document:
RPDIS→ text {INCLUDEPICTURE c:\xxx\xxx.png" \*MERGEFORMAT} text ←RPDIS
Where:
RPDIS→ and ←RPDIS are start and end delimiters
Between the start and end delimiters there can be just text or text and fields with variable content
The * wildcard in the Word Find and Replace dialog box will find the pattern if it contains text only but it will ignore patterns where text is combined with fields. And ^19 will find the field but not the rest of the pattern until the end delimiter.
Can anyone help, please?
Here's a VBA solution. It wildcard searches for RPDIS→*←RPDIS. If the found text contains ^19 (assuming field codes visible; if objects are visible instead of field codes, then the appropriate test is text contains ^01), the found text is deleted. Note that this DOES NOT care about the type of embedded field --- it will delete ANY AND ALL embedded fields that occur between RPDIS→ and ←RPDIS, so use at your own risk. Also, the code has ChrW(8594) and ChrW(8592) to match right-arrow and left-arrow respectively. You may need to change that if your arrows are encoded differently.
Sub test()
Dim wdDoc As Word.Document
Dim r As Word.Range
Dim s As String
' Const c As Integer = 19 ' Works when field codes are visible
Const c As Integer = 1 ' Works when objects are visible
Set wdDoc = ActiveDocument
Set r = wdDoc.Content
With r.Find
.Text = "RPDIS" & ChrW(8594) & "*" & ChrW(8592) & "RPDIS"
.MatchWildcards = True
While .Execute
s = r.Text
If InStr(1, s, chr(c), vbTextCompare) > 0 Then
Debug.Print "Delete: " & s
' r.Delete ' This line commented out for testing; remove comments to actively delete
Else
Debug.Print "Keep: " & s
End If
Wend
End With
End Sub
Hope that helps.

Powershell GUI Imported text file missing newline/carriage return

I have a powershell GUI which imports a text file and displays it in a textbox when a button is clicked
But even though the text file contains one entry per line when it gets displayed in the textbox it is all on one line...
The text file looks like this-
But when I import it it looks like this-
This is the code I am using-
$button_hosts = New-Object system.windows.Forms.Button
$button_hosts.Text = "Hosts"
$button_hosts.Width = 60
$button_hosts.Height = 25
$button_hosts.location = new-object system.drawing.point(20,55)
$button_hosts.Font = "Microsoft Sans Serif,10"
$mydocs = [Environment]::GetFolderPath('MyDocuments')
$button_hosts.Add_Click({
$textBox_hosts.Text = Get-Filename "$mydocs" txt
$textBox_hostlist.Text = Get-Content $textBox_hosts.Text
})
$GUI.controls.Add($button_hosts)
Any idea how to get it to display the same? I cant add any extra data to the txt file as it is an output from another program
Set the lines property, not the text property.
$textBox_hostlist.Lines = Get-Content $textBox_hosts.Text
Get-Content reads the content one line at a time and returns a collection of objects, each of which represents a line of content.
The means that you have to join the collection with carriage returns and linefeeds:
(Get-Content $textBox_hosts) -Join "`r`n"
For your WinForms TextBox, do you have the multiline property set to true?
https://msdn.microsoft.com/en-us/library/12w624ff(v=vs.110).aspx
If not, it defaults to single line.

How to capture a WebElement value using QTP and put that value in the body of an e-mail in the middle of a sentence

I found a similar question that asks how to get a value of a WebElement and put it in an excel file and then e-mail the excel file, but how do I put that value of a WEbElement in the body of an e-mail in the middle of a sentence and NOT in an excel file?
For example, I want to capture a WebElement that tells me how many coke points I have and then I want to e-mail myself that value. Something like: "You have 500 Coke Points now".
This is what I have, but i'm getting a syntax error:
Dim ResultsFile
Set objOutlook=CreateObject("Outlook.Application")
Set objOutlookMsg=objOutlook.CreateItem(olMailItem)
objOutlookMsg.To="email#email.com"
ResultsFile="C:\Documents and Settings\Administrator\My Documents\CkeZeroPoints.xlsx"
objOutlookMsg.Subject="Coke Zero points"
objOutlookMsg.Body="You now have" &Browser("Sweepstakes.*").Page("Sweepstakes.*").WebElement("htmlID:=glPointsText").GetRoProperty("innertext") "Coke Zero points."
objOutlookMsg.Attachments.Add(ResultsFile)
objOutlookMsg.Display
objOutlookMsg.Send
Set objOutlookMsg=Nothing
Set objOutlook=Nothing
The syntax error starts on line 7.
Thank you in advance.
You forgot an ampersand (&):
Dim ResultsFile, innerText
Set objOutlook=CreateObject("Outlook.Application")
Set objOutlookMsg=objOutlook.CreateItem(olMailItem)
' Better to separate tasks so you can trap errors earlier
innerText = Browser("Sweepstakes.*").Page("Sweepstakes.*").WebElement("htmlID:=glPointsText").GetRoProperty("innertext")
ResultsFile = "C:\Documents and Settings\Administrator\My Documents\CkeZeroPoints.xlsx"
' email handling here, you can refactor this in a separate method
objOutlookMsg.To ="email#email.com"
objOutlookMsg.Subject = "Coke Zero points"
objOutlookMsg.Body = "You now have " & innerText & " Coke Zero points." ' <-- ampersand added on this line.
objOutlookMsg.Attachments.Add ResultsFile ' <-- parenthesis removed, only us parenthesis if
' you are calling a (returning) function
objOutlookMsg.Display
objOutlookMsg.Send
Set objOutlookMsg = Nothing
Set objOutlook = Nothing