Get Layout Shape Corresponding to Slide Shape - vba

In PowerPoint 2007 and using VBA, how can I get the placeholder shape on a Slide Master layout that is the "master" for a placeholder shape on the slide?
I am currently using a loop to compare the position and size of the slide placeholder with the position and shape of each placeholder shape in the slide's layout, but this isn't fool-proof. For example, if the placeholder shape is moved on the slide, its position may no longer match the position of any placeholder shapes in the slide's layout. I could reapply the slide's layout to snap placeholders back into position, but that's not what I want to do.
Something in the object model like Shape.Master would be ideal but, of course, that doesn't exist.

Seeing as there is still no answer to this here or elsewhere I might as well post my code.
For example, if the placeholder shape is moved on the slide,
Here's what I came up with to handle that:
store the locations of all shapes
reset the slide layout
match slide shapes and master slide shapes
restore the locations of all shapes.
This is the function that does that and returns a mastershapename - shapename mapping.
private Dictionary<string, string> GetShapeMasters(Powerpoint.Slide s)
{
Dictionary<string, string> shapeMasters = new Dictionary<string, string>();
List<ShapeLocation> shapeLocations = new List<ShapeLocation>();
//store locations
foreach (Powerpoint.Shape sh in s.Shapes)
{
shapeLocations.Add(new ShapeLocation()
{
Name = sh.Name,
Location = new System.Drawing.RectangleF(sh.Left, sh.Top, sh.Width, sh.Height)
});
}
//have powerpoint reset the slide
//ISSUE: this changes the names of placeholders without content.
s.CustomLayout = s.CustomLayout;
//compare slide and master
foreach (Powerpoint.Shape sh in s.Shapes)
{
foreach (Powerpoint.Shape msh in s.CustomLayout.Shapes)
{
if (IsShapeMaster(sh, msh))
{
shapeMasters[msh.Name] = sh.Name;
}
}
}
//restore locations
//TODO: might be replaced by undo
foreach (var shm in shapeLocations)
{
Powerpoint.Shape sh = null;
try
{
sh = s.Shapes[shm.Name];
}
catch
{
//Fails for renamed placeholder shapes.
//Have yet to find a decent way to check if a shape name exists.
}
//placeholders do not need to be restored anyway.
if (sh != null)
{
sh.Left = shm.Location.Left;
sh.Top = shm.Location.Top;
sh.Width = shm.Location.Width;
sh.Height = shm.Location.Height;
}
}
return shapeMasters;
}
With this you can do
Dictionary<string, string> shapeMasters = GetShapeMasters(theSlide);
if(shapeMasters.ContainsKey("KnownPlaceholderName"))
Powerpoint.Shape KnownShape = theSlide[shapeMasters["KnownPlaceholderName"]];
And here is the comparison function that takes two shapes and checks if they are "equal". Could be extended to make it more precise.
private bool IsShapeMaster(Powerpoint.Shape sh, Powerpoint.Shape msh)
{
return
sh.Left == msh.Left
&& sh.Top == msh.Top
&& sh.Width == msh.Width
&& sh.Height == msh.Height
&& sh.Type == msh.Type
&& sh.PlaceholderFormat.Type == msh.PlaceholderFormat.Type;
}
Little class that stores original shape location
class ShapeLocation
{
public string Name;
public System.Drawing.RectangleF Location;
}
This is code from a C# VSTO Add-in but I suppose it is not that different from VB or other PPT automation types.

Here you go Ryan, I believe this is what you're asking for.
Sub GetLayoutShapeDetails()
Dim myPPT As Presentation
Set myPPT = ActivePresentation
Dim mySlide As Slide
Set mySlide = myPPT.Slides(6)
Dim slideShape As Shape
Dim slideLayoutShape As Shape
Set slideShape = mySlide.Shapes(1)
If slideShape.Type = msoPlaceholder Then
Dim placeHolderType As Integer
placeHolderType = slideShape.PlaceholderFormat.Type
Set slideLayoutShape = mySlide.CustomLayout.Shapes.Placeholders(placeHolderType)
Dim modifiedPlaceHolder As String
modifiedPlaceHolder = "Shape Name: " & slideShape.Name & _
", Left: " & slideShape.Left & _
", Width: " & slideShape.Width
Dim originalPlaceHolder As String
originalPlaceHolder = "Shape Name: " & slideLayoutShape.Name & _
", Left: " & slideLayoutShape.Left & _
", Width: " & slideLayoutShape.Width
Debug.Print modifiedPlaceHolder
Debug.Print originalPlaceHolder
End If
End Sub
EDIT: JAN 16, 2010
Based off of further research, there doesn't not appear to be a way in VBA to find a shape's corresponding exact match in its slide's layout.

Related

Create ImageBox in Microsoft Word document and insert image with Visual Basic

I'm working on a project in VB which has to do with document processing in Microsoft Word. I have difficulty on creating an ImageBox with certain size in a the document. Does anybody have an idea on how to do this? Can it even be done? The goal is to create the ImageBox and then insert an image to this box. The image must stretch and get the size of the ImageBox.
What I've done until now is this:
(...)
Dim NewSize As Size
NewSize = New Size(Width, Height)
ResizedImage = New Bitmap(ImageToInsert, NewSize)
(...)
WordDocument.AddPicture(DirectoryAddress & "\ResizedImage." & ImageExtension)
Though, what this code does, is to insert an image with specified size in the Word document. What I want is, the image to stretch and get the size of the ImageBox that will have been created. I hope I was clear enough.
Thanks in advance!
Well, if you were to look at the properties of the table you're creating, you would see that you have not created a table with a fixed height and width. To do that, you could use something like:
NewTable = WordDoc.Tables.Add(para.Range, 1, 1, 0, 0)
NewTable.Cell(1,1).Width(500)
NewTable.Cell(1,1).Height(389)
NewTable.Cell(1, 1).HeightRule(2)
or, in VBA:
Set NewTable = WordDoc.Tables.Add(para.Range, 1, 1, 0, 0)
NewTable.Cell(1,1).Width = 500
NewTable.Cell(1,1).Height = 389
NewTable.Cell(1, 1).HeightRule = 2
Thanks to #CindyMeister and #macropod I managed to create what I needed. So here is the answer:
Dim rng As Word.Range
(...)
rng = para.Range
(...)
Dim img As Image = Image.FromFile(imagePath)
Dim objtable as Word.Table
'In my case I needed a temporary paragraph to be added for my project and later delete it. If you don't need it, just don't declare it.
Dim tempTablePara As Word.Paragraph = WordDoc.Content.Paragraphs.Add() 'Previously declared WordDoc as Word.Document
objtable = WordDoc.Tables.Add(rng, 1, 1)
objtable.Cell(1, 1).Width = img.Width * 0.75 'width is in pixels, convert to points
objtable.Cell(1, 1).Height = img.Height* 0.75 'height is in pixels, convert to points
objtable.Cell(1, 1).HeightRule = Word.WdRowHeightRule.wdRowHeightExactly ' Done so as the cell to get the same size with the picture
Dim objShapes = objtable.Range.InlineShapes
rng = tempTablePara.Range
tempTablePara.Range.Delete()
objShapes.AddPicture(imagePath)
'add cell borders
With objtable.Rows(1).Cells.Borders
.InsideLineStyle = Word.WdLineStyle.wdLineStyleSingle
.OutsideLineStyle = Word.WdLineStyle.wdLineStyleSingle
End With
Extra. What I was looking for, was to insert an image to an already designed frame in a word document. So for me the pre-designed frame was a one cell table. If you just want to add a frame around a picture then the following code should work just fine.
Dim shape
(...)
shape = WordDoc.InlineShapes.AddPicture(imagePath, Type.Missing, Type.Missing, rng)
rng = shape.Range
Dim objshape As Word.InlineShape
objshape = shape
objshape.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleSingleWavy
objshape.Borders.OutsideColor = Word.WdColor.wdColorBlack
rng.Collapse(Word.WdCollapseDirection.wdCollapseEnd)

Fastest way to split Word document to separate files

I'm looking for most efficient way to split one huge file to small files. Every small file is one paragraph from big one.
It's not a problem if big file has ~100 paragraphs, but if its over 12k its took to long time.
Now I'm seting bookmark for each paragraph and next I'm inserting each bookmark in new file (I'm seting bookmark beacause sometimes I have to insert more than one paragraph, but now I don't want complicate exapmple, so I'm describe my problem using paragraphs).
This is my code (ofc its a simple example without extra logic and error handling).
Creation new file, save and close takes the most time.
Private Sub InsertBookmarks()
Dim p As Paragraph
Dim counter As Long
For Each p In ActiveDocument.Paragraphs
counter = counter + 1
ActiveDocument.Bookmarks.Add "File" & Format(counter, "00000#"), p.Range
Next p
ActiveDocument.Save
Set p = Nothing
End Sub
Private Sub SplitToSeparateFiles()
Dim path As String
Dim doc As Document
Dim b As Bookmark
path = ActiveDocument.path & "\"
WordBasic.DisableAutoMacros
For Each b In ActiveDocument.Bookmarks
Set doc = Documents.Add(Visible:=False)
doc.Range.FormattedText = b.Range
doc.SaveAs2 FileName:=path & b.Name
doc.Close wdDoNotSaveChanges
Next b
Set b = Nothing
Set doc = Nothing
End Sub
I considered the change my code to handle splitting using WordOpenXml behind the scenes but I didn't find any solution.
I may use VSTO add-in if someone has any idea in .net environment.
Any idea for more efficient way?
Here's an excerpt from a C# program I use that uses the FreeSpire.Doc nuget package to read a Word Document. I know your questions was VBA but you mentioned .NET at the end, so I figure you're not averse to creating something in C# or VB (vsual studio should be free for small time use)
using (Document document = new Document())
{
document.LoadFromFileInReadMode(#"C:\temp\word.docx", FileFormat.Docx);
foreach (Section s in document.Sections)
{
int pCount = 0;
foreach (Paragraph p in s.Paragraphs)
{
File.WriteAllText(#"c:\temp\p"+pCount+".txt", p.Text);
pCount++;
}
}
}
I don't expect it will take several hours to write 12,000 files, but I don't have a word document with 12,000 paragraphs to test it with; let me know your results?
Edit:
The following program created 12000 files in 41 seconds on an SSD equipped Core i7:
using System;
using System.IO;
namespace ConsoleApp4
{
class Program
{
static void Main()
{
for(int i = 0; i < 12000; i++){
File.WriteAllText(#"c:\temp\x\" + i + ".txt", Guid.NewGuid().ToString());
}
}
}
}
Using it as a benchmark and assuming that it could take up to a minute to load a massive document, I would be hopeful that a .NET app doing the splitting would take a few minutes on a word doc with tens of thousands of paragraphs
Edit2:
Creating word files. The real process might be like this, if you're reading every paragraph out of a source and making a new doc with that same paragraph (try assigning the old paragraph to the new document):
using (Document document = new Document())
{
document.LoadFromFileInReadMode(#"C:\temp\word.docx", FileFormat.Docx);
foreach (Section s in document.Sections)
{
int pCount = 0;
foreach (Paragraph p in s.Paragraphs)
{
Document document = new Document();
Section s = document.AddSection();
s.Paragraphs.Add(p);
document.SaveToFile(#"c:\temp\x\" + pCount + ".docx", FileFormat.Docx);
}
}
}
I created 1200 word documents in 15 seconds:
static void Main()
{
for(int i = 0; i < 1200; i++){
Document document = new Document();
Section s = document.AddSection();
Paragraph p = s.AddParagraph();
TextRange textRange1 = p.AppendText(Guid.NewGuid().ToString());
textRange1.CharacterFormat.TextColor = Color.Blue;
textRange1.CharacterFormat.FontSize = 15;
textRange1.CharacterFormat.Bold = true;
TextRange textRange2 = p.AppendText(Guid.NewGuid().ToString());
textRange2.CharacterFormat.TextColor = Color.Black;
textRange2.CharacterFormat.FontSize = 10;
TextRange textRange3 = p.AppendText(Guid.NewGuid().ToString());
textRange3.CharacterFormat.TextColor = Color.Red;
textRange3.CharacterFormat.FontSize = 8;
textRange3.CharacterFormat.Italic = true;
document.SaveToFile(#"c:\temp\x\" + i + ".docx", FileFormat.Docx);
Console.Out.Write("\r" + i);
}
}
I did note that there was a huge amount of garbage collection going on. Reducing that would perhaps speed things up a bit, if you can work out how

VBA - PowerPoint Macro - Add Text Box content to Outline View

I have PowerPoints that are automatically generated from software. The software puts the content (text) into Text Boxes instead of placeholders. I need to create and run a macro that will add all of the text to the Outline View (for Accessibility purposes).
I have a script that will move the text box content into the placeholder which by default shows up in the outline view. The only problem with this is that it is not retaining the styling (bulleted lists with subbullets are not working). The styling becomes especially problematic when I combine multiple Text Boxes from one slide into a single placeholder.
Any thoughts?
Here is my current script (the important stuff):
For Each sld In ActivePresentation.Slides
With ActivePresentation
sld.CustomLayout = ActivePresentation.Designs(1).SlideMaster.CustomLayouts(2)
Set hypCollection = New hyperColl 'Set the collection of arrays - 1 for each shape
Set shp = sld.Shapes(1)
For j = sld.Shapes.Count To 1 Step -1
Set shp = sld.Shapes(j)
bolCopy = False
If j = 3 Then
sld.Shapes.Placeholders.Item(1).TextFrame.TextRange = shp.TextFrame.TextRange.Characters
sld.Shapes.Placeholders.Item(1).Visible = msoTrue
shp.Delete
ElseIf j > 3 And shp.Type = msoTextBox Then
sld.Shapes.Placeholders.Item(2).TextFrame.TextRange.InsertBefore (shp.TextFrame.TextRange.TrimText) '.ParagraphFormat.Bullet.Type = shp.TextFrame.TextRange.ParagraphFormat.Bullet.Type
If hypCollection.Exists(shp.Name) Then
hypArray = hypCollection.GetArray(shp.Name)
For i = LBound(hypArray) To UBound(hypArray)
Set hypToAdd = hypArray(i)
With sld.Shapes.Placeholders.Item(2).TextFrame.TextRange.Characters(hypToAdd.getchrStart, Len(hypToAdd.getHypText)).ActionSettings.Item(1)
.Action = ppActionHyperlink
.Hyperlink.Address = hypToAdd.getHypAddr
End With
Next i
End If
shp.Delete
End If
Next j
End With
Next sld
Here are some examples:
The First Image is what I start with:
This is what it looks like after running my script:
This is what I want it to look like (simply maintaining formatting):
Would resetting the slide help?
You could add the line:
CommandBars.ExecuteMso ("SlideReset")
Just before:
Next sld
That should set the formatting in the textbox to the way it is on the master.
The fix was to Paste Special into the the new placeholder without replacing all contents. Since I was iterating through the textboxes in reverse order, I simply copied each TextBox and then Pasted Special into the placeholder at position 0 (leaving all current content there).
I converted the code to C#, and this is the full solution:
private void FixPPTDocument()
{
PPT.Application pptApp = new PPT.Application();
PPT.Shape currShp;
PPT.Shape shp2;
if (File.Exists((string)fileLocation))
{
DateTime today = DateTime.Now;
PPT.Presentation pptDoc = pptApp.Presentations.Open(fileLocation, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse);
foreach (PPT.Slide slide in pptDoc.Slides)
{
slide.CustomLayout = pptDoc.Designs[1].SlideMaster.CustomLayouts[2];
for (int jCurr = slide.Shapes.Count; jCurr >= 1; jCurr--)
{
currShp = slide.Shapes[jCurr];
if (jCurr == 3)
{
slide.Shapes.Placeholders[1].TextFrame.TextRange.Text = currShp.TextFrame.TextRange.Text;
slide.Shapes.Placeholders[1].Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
currShp.Delete();
}
else if (jCurr > 3 && currShp.Type == Microsoft.Office.Core.MsoShapeType.msoTextBox)
{
currShp.TextFrame.TextRange.Copy();
slide.Shapes.Placeholders[2].TextFrame.TextRange.Characters(0, 0).PasteSpecial();
currShp.Delete();
}
}
}
pptDoc.SaveAs(fileNewLocation);
pptDoc.Close();
MessageBox.Show("File created!");
}
}

VB code searching all excel file in given folder or directory

Please see below code its working fine and searching for all excel files in given directory. But I am not able to understand this code
Doubt : NoOfFolders(Iterator1) is a dynamic array and when again function is called fnFolderStructure , NoOfFolders array is again created. But even values NoOfFolders(0) and NoOfFolders(1) changed but still when again its is called with previous values.
How it is able to retain values even after writing of NoOfFolders(Iterator1).
fnCheckFiles("C:\Temp\Sahil")
Function fnFolderStructure(sAddress)
i=0
Dim NoOfFolders()
Set objFSO1 = CreateObject("Scripting.FileSystemObject")
Set objFolder2 = objFSO1.GetFolder(sAddress)
Set FolderIn=objFolder2.SubFolders
Set FileIn=objFolder2.Files
' If FileIn.Count>0 Then
' fnCheckFiles(sAddress)
' End If
If FolderIn.Count>0 Then
y=FolderIn.Count
ReDim NoOfFolders(y-1)
For Each objSubfolder in FolderIn
NoOfFolders(i)= objSubfolder.Name
i=i+1
Next
For Iterator1 = 0 To y-1
sPath1=sAddress&"\"&NoOfFolders(Iterator1)
fnCheckFiles(sPath1)
Next
' Set colSubfolders = FolderIn.Subfolders
' Call fnFolderStructure(sPath1)
End If
End Function
Function fnCheckFiles(sAddress)
Set objFSO1 = CreateObject("Scripting.FileSystemObject")
Set objFolder4 = objFSO1.GetFolder(sAddress)
''sFileName=objFolder4.Name
For Each objFile In objFolder4.Files
sFileName=objFile.Name
if (InStr(1,sFileName,"xlsx",1)) then
msgbox objFile.Name
End IF
Next
if objFolder4.SubFolders.Count>0 then
fnFolderStructure(sAddress)
End if
End Function
How it is able to retain values even after writing of
NoOfFolders(Iterator1)
The array is not being written to by that statement. The array NoOfFolders is used in four places...
1) Declares the value as a dynamic array
Dim NoOfFolders()
2) Redimensions the variable to match the size of the number of folder names it will hold
ReDim NoOfFolders(y - 1)
3) Assigns the name of a folders to the corresponding position in the array. This is the only place where values are written to the array.
NoOfFolders(i) = objSubFolder.Name
4) Reads the name of a folder from the array to build a path of a sub-folder
sPath1 = sAddress & "\" & NoOfFolders(Iterator1)
====================================================================================================================*/
def getTagValue(def filepath, def tagName,log)
{
def tagValue = ""
try
{
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance()
DocumentBuilder docBuilder = docFactory.newDocumentBuilder()
Document doc = docBuilder.parse(filepath)
// Get the root element
Node company = doc.getFirstChild()
NodeList nodes = doc.getElementsByTagName(tagName)
//log.info "Nodes length :" +nodes.getLength()
Node node = nodes.item(0)
//log.info node.getTextContent()
tagValue = node.getTextContent()
if(tagValue == "")
{
tagValue = "tag not found"
}
}
catch(Exception e)
{
log.error e.message
tagValue = "tag not found"
}
return tagValue
}
==============================
def List readXpaths(def expectedExcelPath, def expectedExcelSheet, log, context)
{
Fillo.Connection con=getFilloConnection(expectedExcelPath,log)
String sQuery="Select * from "+expectedExcelSheet+" where TestCaseName='"+context.testCase.name+"'"
//log.info sQuery
Recordset rs=getRecordSet(con,sQuery,log)
List<String> colList=rs.getFieldNames()
colList.remove("TestCaseName")
colList.remove("DATA_SET")
colList.remove("RUN")
List<String> xpaths=new ArrayList<String>()
while(rs.next())
{
for(String str:colList)
{
if(rs.getField(str)!="")
{
xpaths.add(rs.getField(str))
}
}
}
return xpaths;
}

How to align each paragraph specifically by Word Interop?

This is my code:
Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim oTable As Word.Table
Dim oPara1 As Word.Paragraph, oPara2 As Word.Paragraph
Dim oPara3 As Word.Paragraph, oPara4 As Word.Paragraph
Dim oRng As Word.Range
oWord = CreateObject("Word.Application")
oWord.Visible = True
oDoc = oWord.Documents.Add
oPara1 = oDoc.Content.Paragraphs.Add
oPara1.Range.InlineShapes.AddPicture(sNewData.Picture)
oPara1.Format.SpaceAfter = 24
oPara1.Range.InsertParagraphAfter()
oPara2 = oDoc.Content.Paragraphs.Add
oPara2.Range.Text = nTP.Nama
oPara2.Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter
oPara2.Range.Font.Bold = True
oPara2.Range.Font.Size = 18
oPara2.Range.Font.Color = Word.WdColor.wdColorBlue
oPara2.Format.SpaceAfter = 6
oPara2.Range.InsertParagraphAfter()
oPara3 = oDoc.Content.Paragraphs.Add
oPara3.Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft
oPara3.Range.Text = "Special arrangement for Mr/Mrs. " & customer
oPara3.Range.Font.Color = Word.WdColor.wdColorOliveGreen
oPara3.Format.SpaceAfter = 3
oPara3.Range.InsertParagraphAfter()
The strange thing is the oPara1 is aligned at left, while oPara2 is aligned at center. But the oPara3 is not aligned at left.
The output is that oPara3 is following the previous alignment which is center.
So how could I apply for a specific paragraph its own alignment or style?
I found some discussion about "Style" but I confused.
This C# code aligns the whole Word document successfully:
foreach (Paragraph p in oWord.ActiveDocument.Paragraphs)
{
p.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
}
Your proposal was right, BUT:
When you you modify the property TEXT in the code, the Alignment property restart to Left.
You can try this inserting several times this code to "debug" the status of the Alignment property. One before you set the alignment, one after you modify the alignment, one after you change the "Text" property, then run the program.
Msgbox(oPara3.Range.ParagraphFormat.Alignment)
So the solution is to modify the Alignment just before inserting the Paragraph:
oPara3 = oDoc.Content.Paragraphs.Add
/*oPara3.Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft*/
oPara3.Range.Text = "Special arrangement for Mr/Mrs. " & customer
oPara3.Range.Font.Color = Word.WdColor.wdColorOliveGreen
oPara3.Format.SpaceAfter = 3
oPara3.Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft
oPara3.Range.InsertParagraphAfter()
AFAIK, Adding a new paragraph is like pressing Enter / Return, so at first format of a new paragraph sets based on Normal Style then after changing any property of current paragraph, it stored as current format that will apply to new paragraphs from now on.
So to change this behavior that makes all new paragraphs to use same format instead of some situation I can suggest to use a method like this - but in C# -:
public static void AddParagraph(ref Document doc, string text,
WdParagraphAlignment align = WdParagraphAlignment.wdAlignParagraphLeft, ...)
// ... means for other format specifications you can do it same
{
var para = doc.Content.Paragraphs.Add();
para.Alignment = align;
para.Range.Text = text;
}
This is what worked for me
Range content = doc.Content;
Paragraph pText = content.Paragraphs.Add();
Text.Range.Text = "sadfsadfsda"
pText.Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
I know this is old question, but the solutions mentioned here didn't help me.
So i'll post the solution here for ppl like me in hope it will help them.
The thing you need to do is set the Alignment property AFTER setting the Text property (see the code below).
'p1 is going to be right aligned
var p1 = document.Paragraphs.Add(System.Reflection.Missing.Value)
p1.Range.Font.Name = "Calibri"
p1.Range.Font.Size = 18
p1.Range.Text = "right"
p1.Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight
p1.Range.InsertParagraphAfter()
'p2 is going to be center aligned
var p2 = document.Paragraphs.Add(System.Reflection.Missing.Value)
p2.Range.Font.Name = "Calibri"
p2.Range.Font.Size = 16
p2.Range.Text = "center"
p2.Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter
p2.Range.InsertParagraphAfter()
'p3 is going to be left aligned
var p3 = document.Paragraphs.Add(System.Reflection.Missing.Value)
p3.Range.Font.Name = "Calibri"
p3.Range.Font.Size = 14;
p3.Range.Text = "left"
p3.Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft
p3.Range.InsertParagraphAfter()
This is the way it worked for me.
This is worked for me!
Range content = doc.ActiveDocument.Content;
Paragraph pText = content.Paragraphs.Add();
pText.Range.ParagraphFormat.Alignment =
WdParagraphAlignment.wdAlignParagraphRight;
doc.Selection.TypeText("some text");