![]() |
#5
|
||||
|
||||
![]()
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] |
Tags |
flashes, vba code |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
ansentry | Office | 2 | 12-07-2015 07:41 PM |
![]() |
mylittleturbott | Office | 2 | 03-17-2014 03:18 PM |
![]() |
noelr | Word Tables | 3 | 10-02-2013 02:19 PM |
![]() |
pask | Outlook | 5 | 03-16-2012 08:43 AM |
screen flashes black when writing | docsobeck | PowerPoint | 0 | 02-01-2010 11:09 AM |