![]() |
|
#1
|
||||
|
||||
![]()
Try:
Code:
Sub InsertPicsToPDF() Application.ScreenUpdating = False Dim Para As Paragraph, Str As String, i As Long, Rng As Range, sPath As String sPath = "K:\test\images\" With ActiveDocument For Each Para In .Paragraphs Str = Trim(Para.Range.Words.First) If Str Like "###" Then Set Rng = Para.Range With Rng .InsertBefore Chr(12) .Collapse wdCollapseEnd .InsertAfter vbCr .Collapse wdCollapseStart .ParagraphFormat.Alignment = wdAlignParagraphCenter End With .InlineShapes.AddPicture FileName:=sPath & Str & ".jpg", _ LinkToFile:=False, SaveWithDocument:=True, Range:=Rng End If Next .Characters.First.Delete For i = 1 To .ComputeStatistics(wdStatisticPages) Set Rng = ActiveDocument.GoTo(What:=wdGoToPage, Name:=i) Set Rng = Rng.GoTo(What:=wdGoToBookmark, Name:="\page") If Rng.Characters.Last = Chr(12) Then Rng.MoveEnd wdCharacter, -1 Str = Trim(Rng.Words.First) Rng.Copy Documents.Add With ActiveDocument .Range.Paste .SaveAs2 FileName:=sPath & Str & ".pdf", FileFormat:=wdFormatPDF, AddToRecentFiles:=False .Close SaveChanges:=False End With Next End With Set Rng = Nothing Application.ScreenUpdating = True End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#2
|
|||
|
|||
![]()
Hey Pal,
Sorry for the late response. Thanks for the correction in code. Yeah the beginning part isn't necessary to worry about. Your code worked! The only thing, is it inserted the picture the way I described, except it inserted after the first sentence of the paragraph. (See attached photo for an example) citgo.pdf The image appears below the guys name "001 Joe Smith Process Engineer", it should be above the guy's name. Any idea why that might be? Thanks again for your help! Last edited by macropod; 12-03-2012 at 03:21 PM. Reason: Deleted unnecessary quote of entire previous post. |
#3
|
||||
|
||||
![]() Quote:
Code:
With Rng .Collapse wdCollapseStart .InsertBefore Chr(12) & vbCr .MoveStart wdCharacter, 1 .ParagraphFormat.Alignment = wdAlignParagraphCenter End With
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#4
|
|||
|
|||
![]()
Thanks Pal!
Just a quick question, seems to work, sort of, I executed the Macro and got an error on this line Code:
.SaveAs2 FileName:=sPath & Str & ".pdf", FileFormat:=wdFormatPDF, AddToRecentFiles:=False Code:
Rng.Copy |
#5
|
|||
|
|||
![]()
Nope you know what, its definitely not the Rng.Copy aspect, its the
Code:
.SaveAs2 FileName:=sPath & Str & ".pdf", FileFormat:=wdFormatPDF, AddToRecentFiles:=False Sorry for the second post. |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Inserted PDFs become Pixelated in Powerpoint | fongchun | PowerPoint | 0 | 11-26-2012 06:24 PM |
![]() |
mattk561 | Word | 8 | 10-31-2012 08:04 PM |
![]() |
chitownbillj | Word | 1 | 06-30-2012 12:01 AM |
Creating High Quality PDFs from Word 2010 | BrazzellMarketing | Word | 11 | 01-27-2012 01:06 PM |
![]() |
KCD123 | PowerPoint | 4 | 09-28-2011 10:03 AM |