Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: tmoore82/Word-Macros2
base: 23c61a088c
...
head fork: tmoore82/Word-Macros2
compare: 8f8c32426e
  • 5 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Showing with 432 additions and 0 deletions.
  1. +348 −0 CopyCat.txt
  2. +81 −0 PDF-txt-Word.vbs
  3. +3 −0  word-macros2.readme
View
348 CopyCat.txt
@@ -0,0 +1,348 @@
+'CopyCat
+'1.0
+'tmoore82
+'9/7/12
+
+'The following is code that can be used in VB macros for Word.
+'Some will require modification,
+'but most can be copied and pasted directly into a new subroutine
+'It's commented out by default. Remember to uncomment
+'or copy without the apostrophe.
+
+'a
+
+ 'ascii
+ 'Chr(9) = tab (-->)
+ 'chr(10) = line feed (vbLf)
+ 'Chr(11) = manual line break (shift-enter)
+ 'Chr(12) = manual page break
+ 'Chr(13) = vbCrLf (return)
+ 'Chr(14) = column break
+ 'chr(20) = pilcrow -- device control four
+ 'Chr(30) = non-breaking hyphen
+ 'Chr(31) = optional hyphen (-)
+ 'Chr(32) = Space ( )
+ 'chr(33) = exclamation point (!)
+ 'Chr(34) = quotation mark (straight) (")
+ 'chr(46) = period (.)
+ 'chr(58) = colon (:)
+ 'chr(63) = question mark (?)
+ 'chr(145) = opening single smart quote
+ 'chr(146) = closing single smart quote / apostrophe
+ 'chr(147) = opening double smart quote
+ 'chr(148) = closing double smart quote
+ 'chr(149) = bullet
+ 'chr(150) = en dash (-)
+ 'Chr(151) = em dash (--)
+ 'Chr(160) = nonbreaking space
+ 'chr(173) = hard hyphen
+
+ 'add page numbers in a text box
+ ' With ActiveDocument.Sections(n).Footers(wdHeaderFooterPrimary).PageNumbers
+ ' .Add (wdPageNumberAlignmenLeft), FirstPage:=True
+ ' End With
+ ' ActiveDocument.Sections(n).Footers(wdHeaderFooterPrimary). _
+ ' PageNumbers.NumberStyle = wdPageNumberStyleLowercaseRoman
+
+'c
+
+ 'call macro
+
+ ' Application.Run MacroName:="[MacroName]"
+
+ 'carriage return
+
+ ' Selection.TypeText Text:=Chr(9)
+
+ 'convert integer to string
+
+ ' CStr(i)
+
+ 'counts
+
+ 'Word Count
+ 'ActiveDocument.Words.Count (includes punctuation and pilcrows)
+ 'Page count
+ 'ActiveDocument.ComputeStatistics(wdStatisticPages)
+
+ 'cursor at beginning of document
+
+ ' Selection.HomeKey Unit:=wdStory
+
+ 'cursor at end of document
+ 'Selection.EndKey Unit:=wdStory
+
+'d
+
+ 'delete all the headerfooters
+
+ 'Sub DeleteHeadFoot()
+ ' Dim oHF As HeaderFooter
+ ' Dim oSection As Section
+ '
+ ' For Each oSection In ActiveDocument.Sections
+ ' For Each oHF In oSection.Headers
+ ' oHF.Range.Delete
+ ' Next
+ ' For Each oHF In oSection.Footers
+ ' oHF.Range.Delete
+ ' Next
+ ' Next
+ 'End Sub
+
+ 'display current doc name/handle
+
+ 'MsgBox ActiveDocument.activewindow.Caption
+
+ 'display current line number
+
+ 'MsgBox Selection.Information(wdFirstCharacterLineNumber)
+
+ 'do while
+
+ 'Do While
+
+ 'If Not Selection.Find.Execute Then Exit Do
+
+ 'Loop
+
+'e
+
+'f
+
+ ' find & replace - default
+
+ 'Selection.Find.ClearFormatting
+ 'Selection.Find.Replacement.ClearFormatting
+ 'With Selection.Find
+ ' .Text = ""
+ ' .Replacement.Text = ""
+ ' .Forward = True
+ ' .Wrap = wdFindContinue
+ ' .Wrap = wdFindStop
+ ' .Wrap = wdFindAsk
+ ' .Format = False
+ ' .MatchCase = False
+ ' .MatchWholeWord = False
+ ' .MatchByte = False
+ ' .MatchAllWordForms = False
+ ' .MatchSoundsLike = False
+ ' .MatchWildcards = False
+ ' .MatchFuzzy = False
+ 'End With
+
+ 'Selection.Find.Execute Replace:=wdReplaceAll, wdReplaceOne
+
+ 'formats
+
+ ' wdOpenFormatAllWord A Microsoft Word format that is backward compatible with earlier versions of Microsoft Word.
+ ' wdOpenFormatAuto The existing format.
+ ' wdOpenFormatDocument Microsoft Word format.
+ ' wdOpenFormatEncodedText Encoded text format.
+ ' wdOpenFormatRTF Rich text format (RTF).
+ ' wdOpenFormatTemplate As a Microsoft Word template.
+ ' wdOpenFormatText Unencoded text format.
+ ' wdOpenFormatUnicodeText Unicode text format.
+ ' wdOpenFormatWebPages HTML format.
+ ' wdOpenFormatXML XML format.
+
+
+'g
+
+ 'go to end of the line
+
+ ' Selection.EndKey Unit:=wdLine
+
+ 'go to next window
+ 'Application.Run MacroName:="NextWindow"
+
+ 'go to page
+
+ 'Selection.GoTo What:=wdGoToPage, Which:=[page number]
+
+'h
+
+ ' how "with" works
+
+ ' "with string.string" tells VBA that the following lines ".string=" should be appended to the same string. this eliminates the need to repeat the string
+
+ 'turn off same as previous in all headerfooters
+
+ ' Dim objDoc As Document
+ '
+ ' Dim objSection As Section
+ '
+ ' Set objDoc = ActiveDocument
+ '
+ ' For Each objSection In objDoc.Sections
+ '
+ ' With objSection
+ '
+ ' .Headers(wdHeaderFooterEvenPages).LinkToPrevious = False
+ '
+ ' .Footers(wdHeaderFooterEvenPages).LinkToPrevious = False
+ '
+ ' .Headers(wdHeaderFooterFirstPage).LinkToPrevious = False
+ '
+ ' .Footers(wdHeaderFooterFirstPage).LinkToPrevious = False
+ '
+ ' .Headers(wdHeaderFooterPrimary).LinkToPrevious = False
+ '
+ ' .Footers(wdHeaderFooterPrimary).LinkToPrevious = False
+ '
+ ' End With
+ '
+ ' Next
+ '
+ ' Set objDoc = Nothing
+
+
+'i
+
+ 'insert a section break next page
+
+ 'Selection.InsertBreak Type:=wdSectionBreakNextPage
+
+ 'insert doc no into footers
+
+ 'Application.Run MacroName:="InsertDocNoInFooters"
+
+ 'insert a field
+ ' Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
+ ' PreserveFormatting:=False
+ ' Selection.TypeText Text:="seq [name]"
+ ' Selection.Fields.Update
+ ' Selection.EndKey Unit:=wdLine
+
+'j
+
+'k
+
+'l
+
+'m
+
+ 'maximize window
+
+ ' Word.Application.WindowState = wdWindowStateMaximize
+
+
+ 'minimize window
+
+ ' Word.Application.WindowState = wdWindowStateMinimize
+
+ 'move cursor until character is found
+
+ ' MoveEndUntil cset:="[]"
+
+'n
+
+ 'name of doc, file name & path set to variable
+
+ ' Dim DesDoc As String
+ ' DesDoc = ActiveDocument.Path & "\" & ActiveDocument.activewindow.Caption
+
+ 'new line
+
+ ' (primarily for use within text strings in Visual Basic)
+ ' vbNewLine
+
+'o
+
+ 'open a doc
+
+ 'Documents.Open FileName:=DesDoc
+
+'p
+
+ 'progress bar (from existing form and code)
+ 'UserForm ProgressBar must already exist
+
+ ' Before Loop
+ ' Dim pb As Integer
+ ' pb = 1
+ '
+ ' Inside Loop
+ ' ProgressBar.Show
+ ' Dim sDescription As String
+ ' Dim sPercentComplete As Single
+ ' sDescription = "Macro Progress"'
+ ' sPercentComplete = (pb / ActiveDocument.[units].Count) * 100
+ ' ProgressBar.Increment sPercentComplete, sDescription
+ '
+ ' pb = pb + 1
+ '
+ ' After Loop
+ ' Unload ProgressBar
+
+ 'print a paragraph
+
+ 'Selection.TypeParagraph
+
+'q
+
+'r
+
+ 'readability statistics
+
+ 'Selection.Range.ReadabilityStatistics(n)
+
+ '1 Words
+ '2 Characters
+ '3 Paragraphs
+ '4 Sentences
+ '5 Sentences Per Paragraph
+ '6 Words per Sentence
+ '7 Characters per word
+ '8 Passive Sentences
+ '9 Flesch Reading Ease
+ '10 Flesch-Kincaid Grade level
+
+ 'restore normal view
+
+ 'ActiveDocument.activewindow.View.Type = wdNormalView
+
+ 'return to the main document
+
+ 'activewindow.ActivePane.View.SeekView = wdSeekMainDocument
+
+'s
+
+ 'save current doc to desktop
+
+ 'ActiveDocument.SaveAs2 ("c:\users\mooret\desktop\" & ActiveDocument.activewindow.Caption)
+
+ 'if nothing selected
+
+ '
+
+ 'space
+
+ ' Selection.TypeText Text:=Chr(32)
+
+'t
+
+
+ 'toggle fields on/off
+
+ 'ActiveWindow.View.ShowFieldCodes = Not ActiveWindow.View.ShowFieldCodes
+
+
+'u
+
+ 'undo
+
+ 'ActiveDocument.Undo
+
+'v
+
+'w
+
+'x
+
+'y
+
+'z
+
+
+
View
81 PDF-txt-Word.vbs
@@ -0,0 +1,81 @@
+'PDF-txt-Word
+'1.1
+'9/6/2012 by tmoore82
+
+'This script converts PDFs to plain text, then copies and pastes that plain text to a new Word document
+'This can be used when you want the text from a PDF without any of the formatting,
+'especially when you suspect the document is corrupted.
+
+'Users should save the pdf to their Desktop before running the script.
+
+'string to hold file path (DMM is short for Don't Mind Me, as this is a space for temporary files the user can ignore.)
+Dim strDMM
+strDMM = "C:\dmm"
+
+'make this directory if it doesn't exits
+On Error Resume Next
+MkDir strDMM
+On Error GoTo 0
+
+'get the username to go to the right filepath
+Dim strUser
+strUser = InputBox("What is your username?" & chr(13) & chr(13) & "(Example: [myname])", "Username")
+
+'get the file name to process
+Dim TheFile
+TheFile = InputBox("What is the file name?" & chr(13) & chr(13) & "(Example: [file.pdf])", "Name of File")
+
+'declare some acrobat variables
+Dim AcroXApp
+Dim AcroXAVDoc
+Dim AcroXPDDoc
+
+'open acrobat
+Set AcroXApp = CreateObject("AcroExch.App")
+AcroXApp.Hide
+
+'open the document we want
+Set AcroXAVDoc = CreateObject("AcroExch.AVDoc")
+AcroXAVDoc.Open "c:\Users\" & strUser & "\Desktop\" & TheFile, "Acrobat"
+
+'make sure the acrobat window is active
+AcroXAVDoc.BringToFront
+
+'I don't know what this line does. As with a lot of this, I copied it from code online.
+Set AcroXPDDoc = AcroXAVDoc.GetPDDoc
+
+'activate JavaScript commands w/Acrobat
+Dim jsObj
+Set jsObj = AcroXPDDoc.GetJSObject
+
+'save the file as plain text
+jsObj.SaveAs "C:\dmm\" & "pdf-plain-text.txt", "com.adobe.acrobat.plain-text"
+
+'close the file and exit acrobat
+AcroXAVDoc.Close False
+AcroXApp.Hide
+AcroXApp.Exit
+
+'Create a Word Object
+Dim objWord
+set objWord = CreateObject("Word.Application")
+
+'insert the file into Word
+With objWord
+ .Visible = False
+ .Documents.Add()
+ .Selection.InsertFile "C:\dmm\pdf-plain-text.txt"
+ 'the next three lines lines are to change everything to our default style at work.
+ 'if you just want the plain text and want to go from there, you don't need them.
+ .Selection.WholeStory
+ .Selection.Style="Body Text"
+ .Selection.Homekey
+End With
+
+'make Word visible
+With objWord
+ .Visible = True
+End With
+
+'Remind the user to save
+MsgBox ("Save the document.")
View
3  word-macros2.readme
@@ -0,0 +1,3 @@
+README Test 1.0
+
+Setting up to learn GitHub.

No commit comments for this range

Something went wrong with that request. Please try again.