Hey There
Had to hard this as unsolved due to a delimma I just started encountering. The script was working fine, but just now (literally a few minutes ago) - suddenly when the macro got executed - the script started opening a new word document, then prompting me if I wanted to save that word document
Any idea why that might be, script below, and I also attached a sample.
Thanks
test.docx
Code:
Sub Splitter()
Selection.EndKey Unit:=wdStory
numlets = Selection.Information(wdActiveEndSectionNumber)
If numlets > 1 Then numlets = numlets - 1
Selection.HomeKey Unit:=wdStory
BaseName = "k:\test\images"
For Counter = 1 To numlets
DocName = BaseName & Right("0" & LTrim(Str(Counter)), 10)
ActiveDocument.Sections.First.Range.Cut
Documents.Add
Selection.Paste
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
ActiveDocument.SaveAs FileName:=DocName, FileFormat:=wdFormatPDF
ActiveWindow.Close
Next Counter
End Sub
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
.Collapse wdCollapseStart
.InsertBefore Chr(12) & vbCr
.MoveStart wdCharacter, 1
.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.Paragraphs(2).Range.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
Quote:
Originally Posted by 4mysanity
Hey bud,
Sorry about all that. It seems to have worked this time. That was weird! Just kinda went all finnickie then started to work, hmm. Welp, thank you very much in any sense.
I shall mark this as solved!
|