View Single Post
 
Old 07-23-2018, 09:13 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,366
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

As suspected, you have lots of 'Windows(#).Activate' and 'Selection' code in there. There is no need for either. For example:
you might use:
Code:
Sub GenByChapter()
' Generate Technician questions by chapters
'
Dim p As Paragraph
Dim pstring As String
Dim MaxNumber As Long
Dim TabLocation As Long
Dim QuestionAnswerRange As Range
Dim StartWord As String, EndWord As String, ftest As String
Dim OldChapter As Long
MaxNumber = 0

Dim Doc1 As Document, Doc2 As Document

Windows("2018-2022 Tech Pool Macro.docm").Activate
Set Doc1 = ActiveDocument
Application.ScreenUpdating = False

Set Doc2 = Documents.Open(FileName:="\Users\Kenneth\Documents\Amateur Radio\New q downloads\questions by chapters 2018.docx", _
  ReadOnly:=True, AddToRecentFiles:=False, Visible:=False)
With Doc2
  For Each p In .Paragraphs
    ' convert paragraph to a string of characters
    pstring = Split(p.Range.Text, vbCr)(0)
    TabLocation = InStr(1, pstring, Chr(9))
    MaxNumber = MaxNumber + 1
    ChapterArray(MaxNumber) = Mid$(pstring, 1, TabLocation - 1)
    QuestionArray(MaxNumber) = Mid$(pstring, TabLocation + 1)
  Next p
  ' close the document with the questions by chapter
  .Close False
End With
OldChapter = -9
Set Doc2 = Documents.Add(Template:="Normal", NewTemplate:=False, DocumentType:=0)
Call SetMargins(Doc2)
'...
Application.ScreenUpdating = True
End Sub
'...
Sub SetMargins(Doc As Document)
With Doc.PageSetup
'...
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote