Transcript

Vord2000_Developers_Handbuok/Book.clsVERSION 1.0 CLASSBEGIN MultiUse = -1 'TrueENDAttribute VB_Name = "Book"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = FalseAttribute VB_Exposed = FalseOption Explicit

Const bookName = "Book Project"

Dim bookTitle As StringDim bookAuthor As StringDim bookPages As LongDim bookPrice As CurrencyDim bookPublicationDate As DateDim bookAvailable As Boolean

Property Let Title(strT As String) bookTitle = strTEnd Property

Property Get Title() As String Title = bookTitleEnd Property

Property Let Author(strA As String) bookAuthor = strAEnd Property

Property Get Author() As String Author = bookAuthorEnd Property

Property Let Pages(lngP As Long) bookPages = PagesEnd Property

Property Get Pages() As Long Pages = bookPagesEnd Property

Property Let Price(curP As Currency) bookPrice = curPEnd Property

Property Get Price() As Currency Price = bookPriceEnd Property

Property Let PublicationDate(dtePD As Date) bookPublicationDate = dtePDEnd Property

Property Get PublicationDate() As Date PublicationDate = bookPublicationDateEnd Property

Property Get Available() As Boolean Available = Date >= PublicationDateEnd Property

Sub ShowInfo() Dim strM As String strM = "Title:" & vbTab & bookTitle & vbCr strM = strM & "Author:" & vbTab & bookAuthor & vbCr strM = strM & "Pages:" & vbTab & bookPages & vbCr strM = strM & "Price:" & vbTab & "$" & bookPrice & vbCr strM = strM & "Date:" & vbTab & Me.PublicationDate & vbCr If Me.Available Then strM = strM & vbCr & "AVAILABLE NOW" MsgBox strM, vbOKOnly + vbInformation, bookName _ & " Information"End Sub

Vord2000_Developers_Handbuok/frmCreateFolders.frmVERSION 5.00Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} frmCreateFolders Caption = "Create Folders" ClientHeight = 2385 ClientLeft = 45 ClientTop = 330 ClientWidth = 3975 OleObjectBlob = "frmCreateFolders.frx":0000 StartUpPosition = 1 'CenterOwnerEndAttribute VB_Name = "frmCreateFolders"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = TrueAttribute VB_Exposed = FalseOption Explicit

Private Sub cmdCancel_Click() frmCreateFolders.Hide Unload frmCreateFolders EndEnd Sub

Private Sub cmdOK_Click() Dim strMsg As String Dim strFolderName As String Dim i As Integer frmCreateFolders.Hide Unload frmCreateFolders strMsg = "The Create_Folders procedure has created " _ & "the following folders: " & vbCr & vbCr For i = 1 To txtHowManyFolders.Value If i < 10 Then strFolderName = txtISBN.Value & "c0" & i Else strFolderName = txtISBN.Value & "c" & i End If MkDir strFolderName strMsg = strMsg & " " & strFolderName & vbCr Next i MsgBox strMsg, vbOKOnly + vbInformation, _ "Create Folders"End Sub

Vord2000_Developers_Handbuok/frmCreateFolders.frxVord2000_Developers_Handbuok/frmCreateFoldersAndSubfolders.frmVERSION 5.00Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} frmCreateFoldersAndSubfolders Caption = "Create Folders and Subfolders" ClientHeight = 2175 ClientLeft = 45 ClientTop = 330 ClientWidth = 3450 OleObjectBlob = "frmCreateFoldersAndSubfolders.frx":0000 StartUpPosition = 1 'CenterOwnerEndAttribute VB_Name = "frmCreateFoldersAndSubfolders"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = TrueAttribute VB_Exposed = FalsePrivate Sub cmdOK_Click() frmCreateFoldersAndSubfolders.Hide Unload frmCreateFoldersAndSubfolders StartingFolder = CurDir For i = 1 To txtHowManyFolders.Value If i < 10 Then FolderName = txtISBN.Value & "c0" & i Else FolderName = txtISBN.Value & "c" & i End If MkDir FolderName ChDir FolderName For Subfolder = 1 To txtHowManySubfolders.Value SubfolderName = "Section" & Subfolder MkDir SubfolderName Next Subfolder ChDir StartingFolder Next iEnd Sub

Private Sub cmdCancel_Click() EndEnd Sub

Vord2000_Developers_Handbuok/frmCreateFoldersAndSubfolders.frxVord2000_Developers_Handbuok/frmDataSurfer2000.frmVERSION 5.00Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} frmDataSurfer2000 Caption = "DataSurfer2000" ClientHeight = 6150 ClientLeft = 45 ClientTop = 330 ClientWidth = 5430 OleObjectBlob = "frmDataSurfer2000.frx":0000 StartUpPosition = 1 'CenterOwnerEndAttribute VB_Name = "frmDataSurfer2000"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = TrueAttribute VB_Exposed = False

Private Sub cmdAddRecord_Click() ActiveDocument.Tables(1).Rows(ActiveDocument.Tables(1).Rows.Count).Select Selection.InsertRowsBelow 1 'and add a tab to the tab strip 'this isn't working yet tabSurfer.Tabs.Add , Index:=tabSurfer.Tabs.Count + 1End Sub

Private Sub cmdClose_Click() 'update all the records? EndEnd Sub

Private Sub tabSurfer_Change() UpdateDataSurferEnd Sub

Sub UpdateDataSurfer() With ActiveDocument.Tables(1).Rows(tabSurfer.Value + 2) txtFirstName.Text = Left(.Cells(1).Range.Text, _ Len(.Cells(1).Range.Text) - 2) txtInitial.Text = Left(.Cells(2).Range.Text, _ Len(.Cells(2).Range.Text) - 2) txtLastName.Text = Left(.Cells(3).Range.Text, _ Len(.Cells(3).Range.Text) - 2) txtAddress1.Text = Left(.Cells(4).Range.Text, _ Len(.Cells(4).Range.Text) - 2) txtAddress2.Text = Left(.Cells(5).Range.Text, _ Len(.Cells(5).Range.Text) - 2) txtCity.Text = Left(.Cells(6).Range.Text, _ Len(.Cells(6).Range.Text) - 2) txtState.Text = Left(.Cells(7).Range.Text, _ Len(.Cells(7).Range.Text) - 2) txtZip.Text = Left(.Cells(8).Range.Text, _ Len(.Cells(8).Range.Text) - 2) txtHomeArea.Text = Left(.Cells(9).Range.Text, _ Len(.Cells(9).Range.Text) - 2) txtHomePhone.Text = Left(.Cells(10).Range.Text, _ Len(.Cells(10).Range.Text) - 2) txtWorkArea.Text = Left(.Cells(11).Range.Text, _ Len(.Cells(11).Range.Text) - 2) txtWorkPhone.Text = Left(.Cells(12).Range.Text, _ Len(.Cells(12).Range.Text) - 2) txtWorkExtension.Text = Left(.Cells(13).Range.Text, _ Len(.Cells(13).Range.Text) - 2) txtEmail.Text = Left(.Cells(14).Range.Text, _ Len(.Cells(14).Range.Text) - 2)

End WithEnd SubPrivate Sub txtFirstName_Change() ActiveDocument.Tables(1).Rows(tabSurfer.Value + 2) _ .Cells(1).Range.Text = txtFirstName.TextEnd SubPrivate Sub txtInitial_Change() ActiveDocument.Tables(1).Rows(tabSurfer.Value + 2) _ .Cells(2).Range.Text = txtInitial.TextEnd SubPrivate Sub txtLastName_Change() ActiveDocument.Tables(1).Rows(tabSurfer.Value + 2) _ .Cells(3).Range.Text = txtLastName.TextEnd SubPrivate Sub txtAddress1_Change() ActiveDocument.Tables(1).Rows(tabSurfer.Value + 2) _ .Cells(4).Range.Text = txtAddress1.TextEnd SubPrivate Sub txtAddress2_Change() ActiveDocument.Tables(1).Rows(tabSurfer.Value + 2) _ .Cells(5).Range.Text = txtAddress2.TextEnd SubPrivate Sub txtCity_Change() ActiveDocument.Tables(1).Rows(tabSurfer.Value + 2) _ .Cells(6).Range.Text = txtCity.TextEnd SubPrivate Sub txtState_Change() ActiveDocument.Tables(1).Rows(tabSurfer.Value + 2) _ .Cells(7).Range.Text = txtState.TextEnd SubPrivate Sub txtZip_Change() ActiveDocument.Tables(1).Rows(tabSurfer.Value + 2) _ .Cells(8).Range.Text = txtZip.TextEnd SubPrivate Sub txtHomeArea_Change() ActiveDocument.Tables(1).Rows(tabSurfer.Value + 2) _ .Cells(9).Range.Text = txtHomeArea.TextEnd SubPrivate Sub txtHomePhone_Change() ActiveDocument.Tables(1).Rows(tabSurfer.Value + 2) _ .Cells(10).Range.Text = txtHomePhone.TextEnd SubPrivate Sub txtWorkArea_Change() ActiveDocument.Tables(1).Rows(tabSurfer.Value + 2) _ .Cells(11).Range.Text = txtWorkArea.TextEnd Sub

Private Sub txtWorkPhone_Change() ActiveDocument.Tables(1).Rows(tabSurfer.Value + 2) _ .Cells(12).Range.Text = txtWorkPhone.TextEnd SubPrivate Sub txtWorkExtension_Change() ActiveDocument.Tables(1).Rows(tabSurfer.Value + 2) _ .Cells(13).Range.Text = txtWorkExtension.TextEnd SubPrivate Sub txtEmail_Change() ActiveDocument.Tables(1).Rows(tabSurfer.Value + 2) _ .Cells(14).Range.Text = txtEmail.TextEnd Sub

Private Sub UserForm_Initialize() With ActiveDocument.Tables(1) 'add the right number of tabs to the tab strip For i = 2 To .Rows.Count tName = Left(.Rows(i).Cells(3).Range.Text, _ Len(.Rows(i).Cells(3).Range.Text) - 2) tabSurfer.Tabs.Add tName Next i 'load the contents of the first row onto the first tab With .Rows(2) txtFirstName.Text = Left(.Cells(1).Range.Text, _ Len(.Cells(1).Range.Text) - 2) txtInitial.Text = Left(.Cells(2).Range.Text, _ Len(.Cells(2).Range.Text) - 2) txtLastName.Text = Left(.Cells(3).Range.Text, _ Len(.Cells(3).Range.Text) - 2) txtAddress1.Text = Left(.Cells(4).Range.Text, _ Len(.Cells(4).Range.Text) - 2) txtAddress2.Text = Left(.Cells(5).Range.Text, _ Len(.Cells(5).Range.Text) - 2) txtCity.Text = Left(.Cells(6).Range.Text, _ Len(.Cells(6).Range.Text) - 2) txtState.Text = Left(.Cells(7).Range.Text, _ Len(.Cells(7).Range.Text) - 2) txtZip.Text = Left(.Cells(8).Range.Text, _ Len(.Cells(8).Range.Text) - 2) txtHomeArea.Text = Left(.Cells(9).Range.Text, _ Len(.Cells(9).Range.Text) - 2) txtHomePhone.Text = Left(.Cells(10).Range.Text, _ Len(.Cells(10).Range.Text) - 2) txtWorkArea.Text = Left(.Cells(11).Range.Text, _ Len(.Cells(11).Range.Text) - 2) txtWorkPhone.Text = Left(.Cells(12).Range.Text, _ Len(.Cells(12).Range.Text) - 2) txtWorkExtension.Text = Left(.Cells(13).Range.Text, _ Len(.Cells(13).Range.Text) - 2) txtEmail.Text = Left(.Cells(14).Range.Text, _ Len(.Cells(14).Range.Text) - 2) End With End WithEnd Sub

'create a CellText function to return the contents of'a cell without the end-of-cell character?

Vord2000_Developers_Handbuok/frmDataSurfer2000.frxVord2000_Developers_Handbuok/frmInventories.frmVERSION 5.00Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} frmInventories Caption = "Inventories 2000" ClientHeight = 4485 ClientLeft = 45 ClientTop = 330 ClientWidth = 3990 OleObjectBlob = "frmInventories.frx":0000 StartUpPosition = 1 'CenterOwnerEndAttribute VB_Name = "frmInventories"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = TrueAttribute VB_Exposed = False

Private Sub UserForm_Initialize() frmInventories.Height = 120End Sub

Private Sub cmdMore_Click() If cmdMore.Caption = "More >>" Then cmdMore.Caption = ">" cmdMore.Accelerator = "M" End IfEnd Sub

Private Sub chkArtNames_Click() If chkArtNames = True Then optFromDocument.Enabled = True optFromDocument = True optAutoNames.Enabled = True Else optFromDocument.Enabled = False optFromDocument = False optAutoNames.Enabled = False optAutoNames = False End IfEnd Sub

Private Sub cmdOK_Click() frmInventories.Hide Unload frmInventories 'create inventories hereEnd Sub

Private Sub cmdCancel_Click() EndEnd Sub

Vord2000_Developers_Handbuok/frmInventories.frxVord2000_Developers_Handbuok/frmMeetingAnnouncement.frmVERSION 5.00Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} frmMeetingAnnouncement Caption = "Meeting Announcement" ClientHeight = 3090 ClientLeft = 45 ClientTop = 330 ClientWidth = 4710 OleObjectBlob = "frmMeetingAnnouncement.frx":0000 StartUpPosition = 1 'CenterOwnerEndAttribute VB_Name = "frmMeetingAnnouncement"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = TrueAttribute VB_Exposed = False'Option Explicit

Private Sub cmdOK_Click() Unload frmMeetingAnnouncement MyText = "The " & cmbMeetingName.Value & _ " meeting will be held in the " _ & cmbMeetingLocation.Value & "." & vbCr _ & "The subject will be " _ & txtMeetingSubject.Text & "." Documents.Add Selection.TypeText Text:=MyText Selection.TypeParagraphEnd Sub

Private Sub UserForm_Initialize() cmbMeetingLocation.AddItem "Main conference room" cmbMeetingLocation.AddItem "Power conference room" cmbMeetingLocation.AddItem "Zen conference room" cmbMeetingName.AddItem "Strategy" cmbMeetingName.AddItem "Sales planning and marketing" cmbMeetingName.AddItem "Acquisitions and reductions" cmbMeetingName.AddItem "Review board considerations"End Sub

Private Sub cmdCancel_Click() EndEnd Sub

Vord2000_Developers_Handbuok/frmMeetingAnnouncement.frxVord2000_Developers_Handbuok/frmMoveCurrentParagraph.frmVERSION 5.00Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} frmMoveCurrentParagraph Caption = "Move Current Paragraph" ClientHeight = 3540 ClientLeft = 45 ClientTop = 330 ClientWidth = 3135 OleObjectBlob = "frmMoveCurrentParagraph.frx":0000 StartUpPosition = 1 'CenterOwnerEndAttribute VB_Name = "frmMoveCurrentParagraph"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = TrueAttribute VB_Exposed = FalsePrivate Sub cmdOK_Click() frmMoveCurrentParagraph.Hide Unload frmMoveCurrentParagraph If chkReturnToPreviousPosition = True Then With ActiveDocument.Bookmarks .Add Range:=Selection.Range, _ Name:="Move_Paragraph_Temp" End With End If Selection.Extend Selection.Extend Selection.Extend Selection.Extend Selection.Cut If optUpOne = True Then Selection.MoveUp Unit:=wdParagraph, Count:=1 ElseIf optUpTwo = True Then Selection.MoveUp Unit:=wdParagraph, Count:=2 ElseIf optDownOne = True Then Selection.MoveDown Unit:=wdParagraph, Count:=1 Else Selection.MoveDown Unit:=wdParagraph, Count:=2 End If Selection.Paste If chkReturnToPreviousPosition = True Then Selection.GoTo What:=wdGoToBookmark, _ Name:="Move_Paragraph_Temp" ActiveDocument.Bookmarks("Move_Paragraph_Temp") _ .Delete End IfEnd Sub

Private Sub cmdCancel_Click() EndEnd Sub

Vord2000_Developers_Handbuok/frmMoveCurrentParagraph.frxVord2000_Developers_Handbuok/frmRegisterTemplates.frmVERSION 5.00Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} frmRegisterTemplates Caption = "Template Installation and Registration" ClientHeight = 2595 ClientLeft = 45 ClientTop = 330 ClientWidth = 7680 OleObjectBlob = "frmRegisterTemplates.frx":0000 StartUpPosition = 1 'CenterOwnerEndAttribute VB_Name = "frmRegisterTemplates"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = TrueAttribute VB_Exposed = False

Option Explicit

Sub Register_Templates() Load frmRegisterTemplates frmRegisterTemplates.ShowEnd Sub

Private Sub cmdChangeInstallationFolder_Click()

frmRegisterTemplates.Hide lblInstallationFolder.Tag = lblInstallationFolder If lblInstallationFolder "" Then If Right(lblInstallationFolder, 1) "\" Then lblInstallationFolder = lblInstallationFolder & "\" If Dir(lblInstallationFolder & "nul") "" Then If Left(lblInstallationFolder, 1) Left(CurDir, 1) Then ChDrive lblInstallationFolder End If ChDir lblInstallationFolder End If End If MsgBox "In the Insert File dialog box, open the folder to use " _ & "as the installation folder. Then click the Cancel button.", _ vbOKOnly + vbInformation, "Choose IntelliBackup Folder" Dialogs(wdDialogInsertFile).Display lblInstallationFolder = CurDir cmdRestoreInstallationFolder.Enabled = True frmRegisterTemplates.Show

End Sub

Private Sub cmdOK_Click() Dim strDestFolder As String Dim strCurFolder As String frmRegisterTemplates.Hide strCurFolder = ActiveDocument.Path strDestFolder = lblInstallationFolder If Dir(strDestFolder, vbDirectory) = "" Then MkDir strDestFolder FileCopy Source:=strCurFolder & "Industry1.dot", _ Destination:=strDestFolder & "\Industry1.dot" FileCopy Source:=strCurFolder & "Industry2.dot", _ Destination:=strDestFolder & "\Industry2.dot" System.PrivateProfileString("", _ "HKEY_CURRENT_USER\Software\Microsoft\" & _ "Office\9.0\Common\SpecialTemplates", _ "RegisteredOwner") = txtRegisteredOwner.Text System.PrivateProfileString("", _ "HKEY_CURRENT_USER\Software\Microsoft\" & _ "Office\9.0\Common\SpecialTemplates", _ "RegisteredOrganization") = txtRegisteredCompany.Text Unload frmRegisterTemplatesEnd Sub

Private Sub cmdRestoreInstallationFolder_Click() lblInstallationFolder = lblInstallationFolder.Tag cmdRestoreInstallationFolder.Enabled = FalseEnd Sub

Private Sub UserForm_Initialize() Dim strCurrVer As String strCurrVer = "HKEY_LOCAL_MACHINE\Software\Microsoft\" _ & System.OperatingSystem & "\CurrentVersion" lblInstallationFolder = Options.DefaultFilePath _ (Path:=wdUserTemplatesPath) & "\Special Templates" txtRegisteredOwner.Text = System.PrivateProfileString("", _ strCurrVer, "RegisteredOwner") txtRegisteredCompany.Text = System.PrivateProfileString("", _ strCurrVer, "RegisteredOrganization")End Sub

Private Sub cmdCancel_Click() EndEnd Sub

Vord2000_Developers_Handbuok/frmRegisterTemplates.frxVord2000_Developers_Handbuok/frmRegistration.frmVERSION 5.00Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} frmRegistration Caption = "Registration" ClientHeight = 2655 ClientLeft = 45 ClientTop = 330 ClientWidth = 5565 OleObjectBlob = "frmRegistration.frx":0000 StartUpPosition = 1 'CenterOwnerEndAttribute VB_Name = "frmRegistration"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = TrueAttribute VB_Exposed = FalseOption Explicit

Private Sub cmdSubmit_Click() Dim strMsg As String Dim strTitle As String strTitle = "Missing Information" If optIndividual.Value = True Then If txtIndividual = "" Then strMsg = "Please enter your name." MsgBox strMsg, vbOKOnly + vbCritical, strTitle Exit Sub End If ElseIf optCompany.Value = True Then If txtCompany = "" Then strMsg = "Please enter your company name." MsgBox strMsg, vbOKOnly + vbCritical, strTitle Exit Sub End If Else strMsg = "Please choose the Individual option button " _ & "or the Company option button." MsgBox strMsg, vbOKOnly + vbExclamation, strTitle Exit Sub End If 'procedure continues here (by hiding the user form, etc.) End Sub Private Sub optCompany_Click() If optCompany.Value = True Then _ optIndividual.Value = False End Sub Private Sub optIndividual_Click() If optIndividual.Value = True Then _ optCompany.Value = FalseEnd Sub

Private Sub cmdCancel_Click() EndEnd Sub

Vord2000_Developers_Handbuok/frmRegistration.frxVord2000_Developers_Handbuok/frmResize.frmVERSION 5.00Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} frmResize Caption = "Resize Event Demo" ClientHeight = 2595 ClientLeft = 45 ClientTop = 330 ClientWidth = 4905 OleObjectBlob = "frmResize.frx":0000 StartUpPosition = 1 'CenterOwnerEndAttribute VB_Name = "frmResize"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = TrueAttribute VB_Exposed = False

Private Sub cmdWidenForm_Click() With frmResize If .Width < 451 Then .Width = .Width + 50 If cmdNarrowForm.Enabled = False Then _ cmdNarrowForm.Enabled = True If .Width > 451 Then _ cmdWidenForm.Enabled = False End If End WithEnd SubPrivate Sub cmdNarrowForm_Click() With frmResize If .Width > 240 Then .Width = .Width - 50 If cmdWidenForm.Enabled = False Then _ cmdWidenForm.Enabled = True If .Width < 270 Then _ cmdNarrowForm.Enabled = False End If End WithEnd SubPrivate Sub cmdClose_Click() Unload MeEnd SubPrivate Sub UserForm_Resize() txt1.Width = frmResize.Width - 30End Sub

Vord2000_Developers_Handbuok/frmResize.frxVord2000_Developers_Handbuok/frmScrollEvent.frmVERSION 5.00Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} frmScrollEvent Caption = "Scroll Event Demo" ClientHeight = 4695 ClientLeft = 45 ClientTop = 330 ClientWidth = 4635 OleObjectBlob = "frmScrollEvent.frx":0000 StartUpPosition = 1 'CenterOwnerEndAttribute VB_Name = "frmScrollEvent"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = TrueAttribute VB_Exposed = False

Dim PrevScroll As IntegerPrivate Sub UserForm_Initialize() ScrollBar1.Min = 0 ScrollBar1.Max = ActiveDocument.Paragraphs.Count txtToEdit.Text = ActiveDocument.Paragraphs(1).Range.TextEnd SubPrivate Sub ScrollBar1_Change() PrevScroll = ScrollBar1.ValueEnd Sub

Private Sub ScrollBar1_Scroll() MyMove = ScrollBar1.Value - PrevScroll If MyMove < 0 Then MyMove = -MyMove Selection.MoveUp Unit:=wdParagraph, Count:=MyMove Else Selection.MoveDown Unit:=wdParagraph, Count:=MyMove End If txtToEdit.Text = Selection.Paragraphs(1).Range.TextEnd Sub

Vord2000_Developers_Handbuok/frmScrollEvent.frxVord2000_Developers_Handbuok/frmTranspose_Three_Words_2000.frmVERSION 5.00Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} frmTranspose_Three_Words_2000 Caption = "Transpose Three Words 2000" ClientHeight = 4695 ClientLeft = 45 ClientTop = 330 ClientWidth = 3870 OleObjectBlob = "frmTranspose_Three_Words_2000.frx":0000 StartUpPosition = 1 'CenterOwnerEndAttribute VB_Name = "frmTranspose_Three_Words_2000"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = TrueAttribute VB_Exposed = False

Option Explicit

Sub Transpose_Three_Words() If Selection.Words.Count 3 Then MsgBox "Please select three words before running this procedure.", vbOKOnly + vbCritical, "Transpose Three Words 1.0" End End If frmTranspose_Three_Words_2000.ShowEnd Sub

Private Sub UserForm_Initialize()

Dim First As String, Second As String, Third As String If Selection.Words.Count < 3 Then Do Until Selection.Words.Count = 3 Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend Loop End If First = Selection.Words(1) Second = Selection.Words(2) Third = Selection.Words(3)

If Right(First, 1) " " Then First = First & " " If Right(Second, 1) " " Then Second = Second & " " If Right(Third, 1) " " Then Third = Third & " "

opt1.Caption = First & Third & Second opt2.Caption = Second & Third & First opt3.Caption = Second & First & Third opt4.Caption = Third & Second & First opt5.Caption = Third & First & Second opt1 = True lblCurrentSelection.Caption = Selection.Text

End Sub

Private Sub cmdOK_Click() frmTranspose_Three_Words_2000.Hide If opt1 = True Then Selection.TypeText opt1.Caption ElseIf opt2 = True Then Selection.TypeText opt2.Caption ElseIf opt3 = True Then Selection.TypeText opt3.Caption ElseIf opt4 = True Then Selection.TypeText opt4.Caption Else Selection.TypeText opt5.Caption End If Unload frmTranspose_Three_Words_2000End Sub

Private Sub cmdCancel_Click() EndEnd Sub

Vord2000_Developers_Handbuok/frmTranspose_Three_Words_2000.frxVord2000_Developers_Handbuok/Word2KDH_05_Non_Listing_Code.basAttribute VB_Name = "Word2KDH_05_Non_Listing_Code"Sub Displaying_Status_Bar_Messages() 'displays a simple message on the status bar Application.StatusBar = _ "The procedure is searching for unsuitable coding. Please wait...." 'clears any message currently displayed on the status bar Application.StatusBar = ""

End Sub

Sub Displaying_Simple_Message_Boxes() 'displays a simple message box with OK button, _ "Microsoft Word" title bar, and no icon MsgBox "This is a simple message box."

'implicitly declares a String variable and displays it _ in a simple message box Prompt$ = "This is a simple message box." MsgBox Prompt$

'example of absurdly long line of code _ displayed in a simple message box Prompt = "Word has finished formatting the report you requested." & vbCr & vbCr & "You can now run the following procedures:" & vbCr & vbCr & Chr(149) & " Distribute_Report will e-mail the report to " & "the head office." & vbCr & vbCr & Chr(149) & " Store_Report will copy the report to the holding directory." & vbCr & vbCr & Chr(149) & " Backup_Report will create a backup " & "of the report on the file server." MsgBox Prompt

'example of the long line of code broken for readability Prompt = "Word has finished formatting the report you requested." _ & vbCr & vbCr & "You can now run the following procedures:" & vbCr _ & vbCr & Chr(149) & " Distribute_Report will e-mail the report to " _ & "the head office." & vbCr & vbCr & Chr(149) & _ " Store_Report will copy the report to the holding directory." _ & vbCr & vbCr & Chr(149) & " Backup_Report will create a backup " _ & "of the report on the file server." MsgBox Prompt

End Sub

Sub Returning_a_Value_from_a_Message_Box()

'displays a message box with Yes and No buttons; _ assigns the user's choice of button to the variable Response Response = MsgBox("Do you want to format the report?", vbYesNo) 'displays a message box with Yes and No buttons; _ assigns the user's choice of button to the variable Response; _ uses the value 4 instead of the constant vbYesNo Response = MsgBox("Do you want to format the report?", 4)

'adds a question-mark icon to the message box Response = MsgBox("Do you want to format the report?", _ vbYesNo + vbQuestion) End Sub

Sub Specifying_a_Default_Button_for_a_Message_Box() 'specifies the second button (the No button) as the default _ for the message box Reply = MsgBox("Do you want to delete this document?", _ vbYesNo + vbCritical + vbDefaultButton2)

End Sub

Sub Specifying_Modality_for_a_Message_Box()

'in theory, displays a system modal message box; _ in practice, you can still access other applications Response = MsgBox("Do you want to delete this document?", _ vbYesNo + vbCritical + vbDefaultButton2 + vbSystemModal)

End Sub

Sub Specifying_a_Title_Bar_for_a_Message_Box()

'specifies Delete Document 1.1 as the title bar for the message box Response = MsgBox("Do you want to delete this document?", vbYesNo _ + vbCritical + vbDefaultButton2, "Delete Document 1.1")

End Sub

Sub Specifying_the_Help_File_and_Context_for_a_Message_Box() 'adds a Help button to a Yes/No message box Response = MsgBox("Do you want to delete this document?", vbYesNo _ + vbCritical + vbDefaultButton2 + vbMsgBoxHelpButton, "Delete Document 1.1")

'specifies a Help file and Help context for the message box 'to make this work, change the Help file to a Help file available _ on your computer, and change the context to a topic that the Help file contains Response = MsgBox("Do you want to format the report?", _ vbYesNo + vbCritical + vbDefaultButton2 + vbMsgBoxHelpButton, _ "Format Report 2.01", "c:\Windows\Help\Procedure Help.hlp", 1012)

End Sub

Sub Returning_the_Button_Chosen_in_a_Message_Box_1()

'direct execution to a label based on the user's choice of button _ in the message box UserChoice = MsgBox("Do you want to create the daily report?", _ vbYesNo + vbQuestion, "Create Daily Report") If UserChoice = vbYes Then GoTo CreateDailyReport Else GoTo Bye End If

'CreateDailyReport: label placed before the appropriate codeCreateDailyReport:

'Bye: label placed at the end of the procedureBye:End Sub

Sub Returning_the_Button_Chosen_in_a_Message_Box_2() 'use an If... Then... ElseIf... Else... statement to direct execution _ appropriately to the button chosen 'assign a sample filename to the NextFile variable NextFile = "c:\temp\Wholly Improbable File.doc" ButtonChosen = MsgBox("Word was unable to find the file:" _ & vbCr & vbCr & NextFile & vbCr & vbCr & _ "Choose the Yes button to search for the file;" & vbCr & _ "choose the No button to skip this file and continue; " _ & vbCr & _ "choose the Cancel button to terminate this procedure.", _ vbYesNoCancel + vbCritical, "Concatenate Files v2.05") If ButtonChosen = vbYes Then DisplaySearchDialog ElseIf ButtonChosen = vbNo Then GoTo SkipCurrentFile Else GoTo Bye End If

'SkipCurrentFile: label placed before the appropriate codeSkipCurrentFile:

'Bye: label placed at the end of the procedureBye:

End Sub

Sub Example_Input_Box() 'displays an input box with a Help button WhichOffice = InputBox( _ "Enter the name of the office that you visited:", _ "Expense Assistant 99", "Madrid", , , _ "c:\Windows\Help\Procedure Help.hlp", 0)

End Sub

Sub DisplaySearchDialog() 'dummy procedure to be called by the _ Returning_the_Button_Chosen_in_a_Message_Box_2 procedure MsgBox "The DisplaySearchDialog procedure would now be running."

End Sub

Vord2000_Developers_Handbuok/Word2KDH_06_Listings.basAttribute VB_Name = "Word2KDH_06_Listings"'Word 2000 Developer's Handbook'Chapter 6 code listings

'Listing 6.1 is in the user form frmMoveCurrentParagraph'Listing 6.2 is in the user form frmMeetingAnnouncement

Vord2000_Developers_Handbuok/Word2KDH_07_Listings.basAttribute VB_Name = "Word2KDH_07_Listings"'Word 2000 Developer's Handbook'Chapter 7 code listings

'Listing 7.1 is in the user form frmInventories'Listing 7.2 is in the user form frmDataSurfer2000'Listing 7.4 is in the user form frmDataSurfer2000'Listing 7.5 is in the user form frmResize'Listing 7.6 is in the user form frmScrollEvent

'Listing 7.3Sub Create_Form()

'declare variables to hold the userform and controls Dim FormToBuild As VBComponent Dim Label1 As Label, Label2 As Label, Label3 As Label Dim TextBox1 As TextBox, TextBox2 As TextBox Dim CommandButton1 As CommandButton, _ CommandButton2 As CommandButton 'create a new userform and assign it to FormToBuild Set FormToBuild = Application.VBE.ActiveVBProject.VBComponents.Add _ (vbext_ct_MSForm) With FormToBuild 'set the properties of the userform by using the Properties collection .Properties("Name") = "frmIncompleteForm" .Properties("Caption") = "Incomplete Form" .Properties("Height") = 140 .Properties("Width") = 180 'add three labels Set Label1 = .Designer.Controls.Add("Forms.Label.1") Set Label2 = .Designer.Controls.Add("Forms.Label.1") Set Label3 = .Designer.Controls.Add("Forms.Label.1") 'add two text boxes Set TextBox1 = .Designer.Controls.Add("Forms.TextBox.1") Set TextBox2 = .Designer.Controls.Add("Forms.TextBox.1") 'add two command buttons Set CommandButton1 = .Designer.Controls.Add("Forms.CommandButton.1") Set CommandButton2 = .Designer.Controls.Add("Forms.CommandButton.1") 'set the properties for the first label With Label1 .Name = "lblMissing" .Left = 10 .Top = 10 .AutoSize = True .WordWrap = False .Caption = "The form is missing the following information:" .TabIndex = 0 End With 'set the properties for the second label With Label2 .Name = "lblUserName" .Left = 10 .Top = 32 .AutoSize = True .WordWrap = False .Caption = "User Name:" .Accelerator = "U" .TabIndex = 1 End With 'set the properties for the third label With Label3 .Name = "lblSecurityID" .Left = 10 .Top = 54 .AutoSize = True .WordWrap = False .Caption = "Security ID:" .Accelerator = "S" .TabIndex = 3 End With 'set the properties for the first text box With TextBox1 .Name = "txtUserName" .Left = 60 .Top = 28 .Width = 100 .TabIndex = 2 End With 'set the properties for the second text box With TextBox2 .Name = "txtSecurityID" .Left = 60 .Top = 48 .Width = 50 .TabIndex = 4 End With 'set the properties for the first command button With CommandButton1 .Name = "cmdOK" .Accelerator = "O" .Caption = "OK" .Left = 20 .Top = 85 .Height = 21 .Width = 55 .TabIndex = 5 .Default = True End With 'set the properties for the second command button With CommandButton2 .Name = "cmdCancel" .Accelerator = "C" .Caption = "Cancel" .Left = 80 .Top = 85 .Height = 21 .Width = 55 .TabIndex = 6 .Cancel = True End With 'assign code to the OK button and Cancel button .CodeModule.AddFromString "Private Sub cmdOK_Click()" & vbCr & _ " frmIncompleteForm.Hide" & vbCr & _ " 'add code for the OK button here." & vbCr & _ "End Sub" & vbCr & vbCr & _ "Private Sub cmdCancel_Click()" & vbCr & _ " End" & vbCr & _ "End Sub" 'end With form structure End With 'display the form frmIncompleteForm.ShowEnd Sub

Vord2000_Developers_Handbuok/Word2KDH_08_Listings.basAttribute VB_Name = "Word2KDH_08_Listings"'Word 2000 Developer's Handbook'Chapter 8 code listings

Sub Listing_8_1() If Documents.Count = 0 Then Proceed = MsgBox("There is no document open." _ & vbCr & vbCr & _ "Please open a document for the procedure to work on.", _ vbOKCancel + vbExclamation, "Format Report 1.13") If Proceed = vbOK Then Dialogs(wdDialogFileOpen).Show If Documents.Count = 0 Then End Else End End If End If 'rest of procedure hereEnd Sub

'Listing 8.2Sub Clear_Find_and_Replace1() Dim dlgMyReplace As Dialog Set dlgMyReplace = Dialogs(wdDialogEditReplace) With dlgMyReplace .Find = "" .Replace = "" .Direction = 0 .MatchCase = False .WholeWord = False .PatternMatch = False .SoundsLike = False .Format = False .FindAllWordForms = False .Show End WithEnd Sub

'Listing 8.3Sub Clear_Find_and_Replace2() With Selection.Find .ClearFormatting .Text = "" .Replacement.ClearFormatting .Replacement.Text = "" .MatchAllWordForms = False .MatchCase = False .MatchSoundsLike = False .MatchWholeWord = False .MatchWildcards = False .Wrap = wdFindContinue .Forward = True End WithEnd Sub

'Listing 8.4

Sub Listing_8_4() Set MyDrop = Dialogs(wdDialogFormatDropCap) With MyDrop .Position = wdDropNormal .Font = "Arial" .DropHeight = 4 .DistFromText = 0.5 BClicked = .Display If BClicked = 0 Then End If .Position wdDropNormal Then _ .Position = wdDropNormal .Execute End WithEnd Sub

'Listing 8.5

Sub Listing_8_5() If Documents.Count = 0 Then Proceed = MsgBox("There is no document open." _ & vbCr & vbCr & _ "Please open a document for the procedure to work on.", _ vbOKCancel + vbExclamation, "Format Report 1.13") If Proceed = vbOK Then ButtonChosen = Dialogs(wdDialogFileOpen).Show If ButtonChosen = 0 Then End Else End End If End If'rest of procedure here

End Sub

Vord2000_Developers_Handbuok/Word2KDH_09_Listings.basAttribute VB_Name = "Word2KDH_09_Listings"'Word 2000 Developer's Handbook'Chapter 9 code listings

'Listing 9.7 is in the user form frmCreateFoldersAndSubfolders

'Listing 9.1

Sub Create_Folders() HowManyFolders = InputBox _ ("Enter the number of folders you want to create.", _ "Create Folders 1.0") ISBN = InputBox("Enter the ISBN to use for the folders.", _ "Create Folders 1.0") For i = 1 To HowManyFolders If i < 10 Then FolderName = ISBN & "c0" & i Else FolderName = ISBN & "c" & i End If MkDir FolderName Next iEnd Sub

'Listing 9.2

Sub GenerateGlossary() Source = ActiveWindow.Caption GlossaryName = InputBox _ ("Enter the name for the glossary document.", _ "Create Glossary 1.0") If GlossaryName = "" Then End Documents.Add ActiveDocument.SaveAs FileName:=GlossaryName, _ FileFormat:=wdFormatDocument Destination = ActiveWindow.Caption Windows(Source).Activate Selection.HomeKey Unit:=wdStory Selection.Find.ClearFormatting Selection.Find.Font.Italic = True Selection.Find.Font.Name = "Times New Roman" Selection.Find.Text = "" Selection.Find.Execute Do While Selection.Find.Found Selection.Copy Selection.MoveRight Unit:=wdCharacter, _ Count:=1, Extend:=wdMove Windows(Destination).Activate Selection.EndKey Unit:=wdStory Selection.Paste Selection.TypeParagraph Windows(Source).Activate Selection.Find.Execute LoopEnd Sub

'Listing 9.3

Sub Lottery() Do Until Win > 2000 Win = Rnd * 2100 MsgBox Win, , "Lottery" LoopEnd Sub

'Listing 9.4

Sub FindNextHeading() Do Until Left(Selection.Paragraphs(1).Style, 7) = "Heading" Selection.MoveDown Unit:=wdParagraph, _ Count:=1, Extend:=wdMove LoopEnd Sub

'Listing 9.5

Sub ListFriends() Do FriendName = InputBox _ ("Enter the name of one of your friends.", _ "List Friends 1.1") Selection.TypeText FriendName + Chr(13) Loop Until FriendName = ""End Sub

'Listing 9.6Sub Lottery2() Do Until Win > 2000 Win = Rnd * 2100 If Win < 500 Then MsgBox "Tough luck. You have been disqualified.", _ vbOKOnly + vbCritical, "Lottery" Exit Do End If MsgBox Win, , "Lottery" LoopEnd Sub

'Listing 9.8

Sub InfiniteLoop() x = 1 Do Application.StatusBar = "Your computer is stuck in an endless loop: " & x x = x + 1 LoopEnd Sub

Vord2000_Developers_Handbuok/Word2KDH_10_Listings.basAttribute VB_Name = "Word2KDH_10_Listings"'Word 2000 Developer's Handbook'Chapter 10 code listings'Listing 10.7 is in the code sheet of the user form _frmMoveParagraphUpOrDownFour

'no Option Explicit declaration for this chapter

Sub Listing_10_01() 'supply the BookPages value via an input box bookPages = InputBox("Enter the number of pages in the book.", _ "The Electronic Book Critic", 1001)

If bookPages > 1000 Then MsgBox "The book is very long.", vbOKOnly _ + vbExclamation, "The Electronic Book Critic" Else MsgBox "The book is not so long.", vbOKOnly _ + vbInformation, "The Electronic Book Critic" End If

End Sub

Sub Listing_10_02()

Response = MsgBox("Do you want to proceed?", vbYesNo _ + vbQuestion, "Create Glossary 1.0") If Response = vbYes Then CreateGlossary Else GoTo Bye End If

'Bye: labelBye:

End Sub

Sub CreateGlossary() 'dummy procedure to be run by Listing_10_02 MsgBox "The CreateGlossary procedure is pretending to run."

End Sub

Sub Listing_10_03()

'assign a file name to the variable strFileToOpen strFileToOpen = "c:\Temp\Bogus File 4549.doc"

Response = MsgBox("Word cannot find " _ & strFileToOpen & "." & vbCr & vbCr _ & "Do you want to search for the file manually?", _ vbYesNoCancel + vbCritical, "Concatenate Documents") If Response = vbYes Then SearchManually ElseIf Response = vbNo Then GoTo ResumeExecution Else End End If 'ResumeExecution: labelResumeExecution: End Sub

Sub SearchManually() 'dummy procedure to be run by Listing_10_0 MsgBox "The SearchManually procedure is pretending to run." End Sub

Sub Listing_10_04()

BadPassword: Password = InputBox _ ("Enter the password to protect this item from changes:", _ "Enter Password") If Len(Password) = 0 Then End ElseIf Len(Password) < 6 Then MsgBox "The password you chose is too short." & vbCr _ & vbCr & "Please choose a password between " & _ "6 and 15 characters in length.", _ vbOKOnly + vbCritical, "Unsuitable Password" GoTo BadPassword ElseIf Len(Password) > 15 Then MsgBox "The password you chose is too long." & vbCr _ & vbCr & "Please choose a password between " & _ "6 and 15 characters in length.", _ vbOKOnly + vbCritical, "Unsuitable Password" GoTo BadPassword End If

End Sub

Sub Listing_10_05()

'to run this code successfully, the active document must contain _ a paragraph formatted with Heading 5 style. The document or its _ attached template must contain the style Special Note.

Selection.HomeKey Unit:=wdStory Selection.Find.ClearFormatting Selection.Find.Style = ActiveDocument.Styles("Heading 5") Selection.Find.Text = "" Selection.Find.Execute If Selection.Find.Found Then Response = MsgBox("Make this into a special note?", _ vbOKCancel, "Make Special Note") If Response = vbOK Then Selection.Style = "Special Note" End If End If

End Sub

Sub Listing_10_06()

TypingSpeed = InputBox _ ("How many words can you type per minute?", _ "Typing Speed") Select Case TypingSpeed Case "" End Case Is < 0, 0, 1 To 50 Msg = "Please learn to type properly before " & _ "applying for a job." Case 50 To 60 Msg = "Your typing could do with a little " & _ "brushing up." Case 60 To 75 Msg = "We are satisfied with your typing speed." Case 75 To 99 Msg = "Your typing is more than adequate." Case 100 To 200 Msg = "You wear out keyboards with your blinding speed." Case Is > 200 Msg = "Liar!" End Select MsgBox Msg, vbOKOnly, "Typing Speed"

End Sub

Vord2000_Developers_Handbuok/Word2KDH_11_Listings.basAttribute VB_Name = "Word2KDH_11_Listings"'Word 2000 Developer's Handbook'Chapter 11 code listings

'Listing 11.5 is in the user form frmFileSelecter2000

Option Explicit

'Listing 11.1Public strCurrentUser As String

Sub AutoExec() strCurrentUser = InputBox("Please enter your name.", _ "Current User Identity")End Sub Sub Identify_Current_User() MsgBox "The current user is " & strCurrentUser, _ vbOKOnly + vbInformation, "Current User"End Sub

'Listing 11.2Sub Save_in_Out_Folder() Dim OName As String, NName As String, _ intToChange OName = ActiveDocument.FullName intToChange = InStr(OName, "\In\") NName = Left(OName, intToChange - 1) & "\Out\" _ & Right(OName, Len(OName) - intToChange - 3) ActiveDocument.SaveAs NNameEnd Sub

'Listing 11.3Sub CheckPassword() Dim strPassword As StringBadPassword: strPassword = InputBox _ ("Enter the password to protect this item from changes:" _ , "Enter Password") If Len(strPassword) = 0 Then End ElseIf Len(strPassword) < 6 Then MsgBox "The password you chose is too short." _ & vbCr & vbCr & _ "Choose a password between 6 and 15 characters in length.", _ vbOKOnly + vbCritical, "Unsuitable Password" GoTo BadPassword ElseIf Len(strPassword) > 15 Then MsgBox "The password you chose is too long." _ & vbCr & vbCr & _ "Choose a password between 6 and 15 characters in length.", _ vbOKOnly + vbCritical, "Unsuitable Password" GoTo BadPassword End IfEnd Sub 'Listing 11.4 Sub Age() Dim Age As Integer, YourAge As String Age = InputBox("Enter your age:", "Age") YourAge = "Your age is" + Str(Age) & "." MsgBox YourAge, vbOKOnly + vbInformation, "Age"End Sub

Vord2000_Developers_Handbuok/Word2KDH_12_Listings.basAttribute VB_Name = "Word2KDH_12_Listings"'Word 2000 Developer's Handbook'Chapter 12 code listings

'Listing 12.1Sub Save_Unsaved_Documents() Dim Doc As Document For Each Doc In Documents If Doc.Saved = False Then If MsgBox("Do you want to save the changes to " _ & Doc.Name & " now?", vbYesNo + vbQuestion, _ "Save Unsaved Documents 2000") = vbYes Then Doc.Save End If Next DocEnd Sub

Vord2000_Developers_Handbuok/Word2KDH_13_Listings.basAttribute VB_Name = "Word2KDH_13_Listings"'Word 2000 Developer's Handbook'Chapter 13 code listings

Option Explicit

'Listing 13.1

Sub Transpose_Three_Words_2000() If Selection.Words.Count 3 Then MsgBox "Please select three words before running " & _ "this procedure.", vbOKOnly + vbCritical, _ "Transpose Three Words 2000" End End If frmTranspose_Three_Words_2000.ShowEnd Sub

'The remainder of Listing 13.1 is in the user form'frmTranspose_Three_Words_2000 'Listing 13.2

Sub RemoveRepeatedParagraphs() Dim intNumParas As Integer, i As Integer Dim FirstRange As Range, SecondRange As Range intNumParas = Documents("Glossary.doc").Paragraphs.Count For i = 1 To intNumParas Set FirstRange = ActiveDocument.Paragraphs(i).Range If i = intNumParas Then Exit For Set SecondRange = ActiveDocument.Paragraphs(i + 1).Range If SecondRange.Text = FirstRange.Text Then FirstRange.Delete i = i - 1 intNumParas = intNumParas - 1 End If Next iEnd Sub

'Listing 13.3

Sub RealTitleCase()

Dim strHeading As String, _ NumWords As Integer, i As Integer strHeading = "" If Selection.Type wdSelectionIP Then _ Selection.Collapse Direction:=wdCollapseStart Selection.Paragraphs(1).Range.Select NumWords = Selection.Words.Count For i = 1 To NumWords Select Case Selection.Words(i) Case "a ", "above ", "after ", "an ", "and ", _ "as ", "at ", "beside ", "but ", "by ", _ "down ", "for ", "from ", "in ", "into ", _ "of ", "off ", "on ", "onto ", "or ", _ "out ", "the ", "to ", "under ", "up ", _ "with ", "within ", "without " If i 1 And i NumWords Then _ Selection.Words(i).Case = wdLowerCase Case "DOS ", "dos ", "FTP ", "ftp ", "HTML ", "html ", _ "HTTP ", "http ", "IP ", "ip ", "TCP ", "tcp " Selection.Words(i).Case = wdUpperCase Case "AutoText ", "AutoCorrect ", "AutoFormat ", _ "AutoFit ", "IntelliSense " Case "autotext " Selection.Words(i).Text = "AutoText " Case "autocorrect " Selection.Words(i).Text = "AutoCorrect " Case "autoformat " Selection.Words(i).Text = "AutoFormat " Case "autofit " Selection.Words(i).Text = "AutoFit " Case "intellisense " Selection.Words(i).Text = "IntelliSense " Case Else Selection.Words(i).Case = wdTitleWord End Select strHeading = strHeading + Selection.Words(i) Application.StatusBar = strHeading Next i Selection.Collapse Direction:=wdCollapseEnd Application.StatusBar = ""End Sub

'Listing 13.4

Sub Listing_13_4() With Documents("Submission.doc").Content.Find .ClearFormatting .Font.Bold = True With .Replacement .ClearFormatting .Font.Bold = False .Font.Italic = True End With .Execute FindText:="", ReplaceWith:="", _ Format:=True, Replace:=wdReplaceAll End WithEnd Sub

'Listing 13.5

Sub ApplyHeading2Rule() With Selection .HomeKey Unit:=wdStoryRuleLoop: With .Find .ClearFormatting .Style = ActiveDocument.Styles("Heading 2") .Text = "" .Forward = True .Wrap = wdFindStop .Format = True End With .Find.Execute If .Find.Found = True Then .MoveLeft Unit:=wdCharacter, Count:=1 .MoveUp Unit:=wdParagraph, Count:=1 If .Style "Heading 2 Rule" Then .MoveDown Unit:=wdParagraph, Count:=1 .InsertParagraph .Style = "Heading 2 Rule" End If .MoveDown Unit:=wdParagraph, Count:=2 Else Exit Sub End If If .Type = wdSelectionIP And Selection.End = _ ActiveDocument.Content.End - 1 Then Exit Sub Else GoTo RuleLoop End If End WithEnd Sub

'Listing 13.6

Sub AutoCorrect_List_All_Entries() Dim objThisAuC As AutoCorrectEntry Documents.Add For Each objThisAuC In AutoCorrect.Entries If objThisAuC.RichText = False Then _ Selection.TypeText objThisAuC.Name _ & vbTab & objThisAuC.Value & vbCr Next objThisAuC For Each objThisAuC In AutoCorrect.Entries If objThisAuC.RichText = True Then Selection.TypeText objThisAuC.Name & vbTab objThisAuC.Apply Range:=Selection.Range Selection.Style = wdStyleDefaultParagraphFont Selection.TypeParagraph End If Next objThisAuCEnd Sub

Vord2000_Developers_Handbuok/Word2KDH_14_Listings.basAttribute VB_Name = "Word2KDH_14_Listings"'Word 2000 Developer's Handbook'Chapter 14 code listings

Option Explicit

'Listing 14.1 Sub Does_File_Exist() Dim strTestFile As String, strNameToTest As String, _ strMsg As String strNameToTest = InputBox("Enter the file name and path:") If strNameToTest = "" Then End strTestFile = Dir(strNameToTest) If Len(strTestFile) = 0 Then strMsg = "The file " & strNameToTest & _ " does not exist." Else strMsg = "The file " & strNameToTest & " exists." End If MsgBox strMsg, vbOKOnly + vbInformation, _ "File-Existence Check"End Sub

'Listing 14.2

Sub Delete_the_Current_File() Dim FileToKill As String, TestFile As String, _ Response As Byte FileToKill = ActiveDocument.FullName Response = MsgBox("Do you want to delete " _ & FileToKill & "?", vbYesNo + vbCritical _ + vbDefaultButton2, "Delete the Current File") If Response = vbYes Then TestFile = Dir(FileToKill) ActiveDocument.Close _ savechanges:=wdDoNotSaveChanges If Len(TestFile) 0 Then Kill FileToKill End If End IfEnd Sub

'Listing 14.3

Sub Copy_an_Open_File() Dim Source As String, SourcePath As String, _ Destination As String Source = ActiveDocument.FullName SourcePath = ActiveDocument.Path _ & Application.PathSeparator Destination = InputBox("Enter the destination for " _ & Source, "Copy Open File 2000", SourcePath) If Destination "" Then ActiveDocument.Close FileCopy Source, Destination Documents.Open FileName:=Source Documents.Open FileName:=Destination Documents(Source).Activate End IfEnd Sub

'Listing 14.4

Sub Move_Open_File() Dim MoveMe As String, MoveFile As String, _ MoveTo As String, CurPath As String MoveFile = ActiveDocument.FullName MoveMe = ActiveDocument.Name CurPath = ActiveDocument.Path MoveTo = InputBox("Enter the destination folder for " _ & MoveMe & vbCr & vbCr & "Current folder: " _ & CurPath, "Move Document") If MoveTo "" Then MoveTo = MoveTo & Application.PathSeparator & MoveMe Documents(MoveFile).Close Name MoveFile As MoveTo Documents.Open MoveTo Application.GoBack End IfEnd Sub

Vord2000_Developers_Handbuok/Word2KDH_15_Listings.basAttribute VB_Name = "Word2KDH_15_Listings"'Word 2000 Developer's Handbook'Chapter 15 code listings

Option Explicit

'Listing 15.1

Sub Update_All_Fields() Dim strTitle As String, strAllLock As String, _ strLock As String, Choice strTitle = "Update All Fields 2000" With ActiveDocument.Fields If .Locked = True Then strAllLock = "All the fields in this document " & _ "are locked, and you will not be able to " & _ "update them. Do you want to unlock " & _ "the locked fields?." If MsgBox(strAllLock, vbYesNo, strTitle) = vbYes Then .Locked = False .Update Else End End If ElseIf .Locked = wdUndefined Then strLock = "Some of the fields in this document " & _ "are locked, and you will not be able to " & _ "update them. Do you want to unlock the " & _ "locked fields before updating the other fields?" Choice = MsgBox(strLock, vbYesNoCancel _ + vbQuestion, strTitle) If Choice = vbYes Then .Locked = False .Update ElseIf Choice = vbNo Then .Update Else 'Choice = vbCancel End End If Else .Update End If End WithEnd Sub

Vord2000_Developers_Handbuok/Word2KDH_16_Listings.basAttribute VB_Name = "Word2KDH_16_Listings"'Word 2000 Developer's Handbook'Chapter 16 code listings

'module-level variable declarations for Listing 16.2Private mUserStory As LongPrivate mUserView As LongPrivate mWasMagnifier As BooleanPrivate mTempBook As Bookmark

Option Explicit

'Listing 16.1

Sub IsParagraphEmpty() If Len(ActiveDocument.Bookmarks("\Para").Range.Text) > 1 Then ActiveDocument.Bookmarks("\Para").Select Selection.Collapse Direction:=wdCollapseEnd If Selection.Text vbCr Then Selection.TypeParagraph Selection.MoveUp Unit:=wdParagraph, Count:=1, _ Extend:=wdMove End If If Selection.End = ActiveDocument.Content.End - 1 Then _ Selection.TypeParagraph End If Selection.TypeText "This is some sample text." 'sample actionEnd Sub

'Listing 16.2

'variable declarations for Listing 16.2 are at the beginning of the module

Sub ExampleActions() SwitchToMainStory 'take actions here RestoreToPreviousStoryEnd Sub

Sub SwitchToMainStory() Set mTempBook = ActiveDocument.Bookmarks.Add("WasHere") If mTempBook.StoryType wdMainTextStory Then With ActiveWindow.View mUserStory = mTempBook.StoryType mUserView = .Type If mUserView = 4 Then mWasMagnifier = .Magnifier .SeekView = wdSeekMainDocument If .SplitSpecial wdPaneNone Then _ .SplitSpecial = wdPaneNone .Type = wdPrintView If mTempBook.StoryType = wdTextFrameStory Then ActiveDocument.Characters(1).Select Selection.Collapse Direction:=wdCollapseStart End If End With End IfEnd Sub

Sub RestoreToPreviousStory() If mUserStory = 4 Then ActiveWindow.View.Type = wdPrintPreview ActiveWindow.View.Magnifier = mWasMagnifier End If If mUserStory 0 Then With ActiveWindow.View .Type = mUserView Select Case mUserStory Case wdCommentsStory .SplitSpecial = wdPaneComments Case wdEndnotesStory If mUserView = wdPageView _ Or mUserView = wdPrintPreview Then .SeekView = wdSeekEndnotes Else .SplitSpecial = wdPaneEndnotes End If Case wdEvenPagesFooterStory .SeekView = wdSeekEvenPagesFooter Case wdEvenPagesHeaderStory .SeekView = wdSeekEvenPagesHeader Case wdFirstPageFooterStory .SeekView = wdSeekFirstPageFooter Case wdFirstPageHeaderStory .SeekView = wdSeekFirstPageHeader Case wdPrimaryFooterStory .SeekView = wdSeekPrimaryFooter Case wdPrimaryHeaderStory .SeekView = wdSeekPrimaryHeader Case wdFootnotesStory If mUserView = wdPageView _ Or mUserView = wdPrintPreview Then .SeekView = wdSeekFootnotes Else .SplitSpecial = wdPaneFootnotes End If Case wdTextFrameStory mTempBook.Select mTempBook.Delete If mUserView = wdPrintPreview Then ActiveWindow.View = wdPrintPreview ActiveWindow.View.Magnifier = mWasMagnifier End If End Select End With End If With ActiveDocument If .Bookmarks.Exists("WasHere") Then .Bookmarks("WasHere").Select .Bookmarks("WasHere").Delete End If End WithEnd Sub

'Listing 16.3

Sub Replacing_a_Bookmark() Dim intMyBookStart As Integer Dim intMyBookEnd As Integer Dim strMyBookContents As String Dim strMyLeft As String Dim strMyRight As String Dim myRange As Range With Documents("Personnel Request.doc") With .Bookmarks("bDescription") intMyBookStart = .Range.Start intMyBookEnd = .Range.End strMyBookContents = .Range.Text End With Set myRange = .Range(Start:=intMyBookStart, _ End:=intMyBookEnd) strMyBookContents = Left(strMyBookContents, _ Len(strMyBookContents) - 4) strMyBookContents = Right(strMyBookContents, _ Len(strMyBookContents) - 3) strMyLeft = Left(strMyBookContents, 5) strMyRight = Right(strMyBookContents, 5) strMyBookContents = "New bookmark: " _ & strMyLeft & ": " & strMyRight & "!" myRange.Text = strMyBookContents .Bookmarks.Add Name:="bDescription", Range:=myRange End WithEnd Sub

'Listing 16.4

Sub RemoveAllHiddenBookmarks() Dim myBook As Bookmark Dim myShowHidden As Boolean With ActiveDocument myShowHidden = .Bookmarks.ShowHidden If myShowHidden = False Then .Bookmarks.ShowHidden = True For Each myBook In .Bookmarks If Left(myBook.Name, 1) = "_" Then myBook.Delete Next myBook If myShowHidden = False Then .Bookmarks.ShowHidden = False End WithEnd Sub

Vord2000_Developers_Handbuok/Word2KDH_17_Listings.basAttribute VB_Name = "Word2KDH_17_Listings"'Word 2000 Developer's Handbook'Chapter 17 code listings

Option Explicit

'Listing 17.1

Sub Format_All_Headers() Dim myDoc As Document, cSection As Section, _ myHeader As HeaderFooter Set myDoc = Documents("Sample Report.doc") With myDoc For Each cSection In .Sections For Each myHeader In cSection.Headers myHeader.LinkToPrevious = False myHeader.Range.Style = "Header Report" Next myHeader Next cSection End WithEnd Sub

'Listing 17.2

Sub Create_Draft_Watermark() Dim MyBox As Shape With ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary) _ .Shapes Set MyBox = .AddTextbox _ (Orientation:=msoTextOrientationHorizontal, _ Left:=100, Top:=200, Height:=150, Width:=400) With MyBox With .TextFrame.TextRange .Text = "Draft" With .Font .Name = "Arial" .Size = "144" .Bold = True End With End With .Line.Visible = msoFalse .Fill.Transparency = 0.5 End With End WithEnd Sub

Vord2000_Developers_Handbuok/Word2KDH_18_Listings.basAttribute VB_Name = "Word2KDH_18_Listings"'Word 2000 Developer's Handbook'Chapter 18 code listings

Option Explicit

'Listing 18.1

Sub RemoveBlankRows()

'Remove the blank rows from the current table Dim i As Integer Dim xCell As Cell Dim BlankRow As Boolean With ActiveDocument For i = 1 To .Tables(1).Rows.Count If .Tables(1).Rows.Count < i Then End With .Tables(1).Rows(i) For Each xCell In .Cells If xCell.Range.Text = Chr(13) & Chr(7) Then BlankRow = True Else BlankRow = False Exit For End If Next xCell If BlankRow = True Then .Delete End With Next i End WithEnd Sub

Vord2000_Developers_Handbuok/Word2KDH_19_Listings.basAttribute VB_Name = "Word2KDH_19_Listings"'Word 2000 Developer's Handbook'Chapter 19 code listings

Option Explicit

'Listing 19.1

Sub StyleError() On Error GoTo Handler Selection.Style = "Executive Summary" GoTo SkipHandlerHandler: If Err = 5834 Then ActiveDocument.Styles.Add _ Name:="Executive Summary", Type:=wdStyleTypeParagraph Resume End IfSkipHandler: 'execution of procedure continues hereEnd Sub

'Listing 19.2Sub Handle_Error_Opening_File() Dim strFName As StringStartHere: On Error GoTo ErrorHandler strFName = InputBox("Enter the name of the file to open.", _ "Open File") If strFName = "" Then End Documents.Open strFName Exit SubErrorHandler: If Err = 5174 Or Err = 5121 Then MsgBox _ "The file " & strFName & " does not exist." & vbCr & _ "Please enter the name again.", _ vbOKOnly + vbCritical, "File Error" Resume StartHereEnd Sub

Vord2000_Developers_Handbuok/Word2KDH_20_Listings.basAttribute VB_Name = "Word2KDH_20_Listings"'Word 2000 Developer's Handbook'Chapter 20 code listings

'Module-level private variable for Listing 20.2Private strPassMe As String

Option Explicit

'Listing 20.1

Sub GetCustomerInfo() Dim strCustName As String, strCustCity As String, _ strCustPhone As String 'Get CustName, CustCity, CustPhone from sources CreateCustomer strCustName, strCustCity, strCustPhoneEnd Sub

Sub CreateCustomer(ByRef strCName As String, _ ByRef strCCity As String, ByVal strCPhone As String) Dim strCustomer As String strCustomer = strCName & vbTab & strCCity _ & vbTab & strCPhone 'take action with strCustomer string hereEnd Sub

'Listing 20.2

'Private variable for Listing 20.2 is declared at the beginning of the module

Sub PassingInfo() strPassMe = "Hello." PassingInfoBack MsgBox strPassMeEnd Sub

Sub PassingInfoBack() strPassMe = strPassMe & " How are you?"End Sub

'Listing 20.3

Sub ShowProfit() MsgBox (NetProfit(44000, 34000)), , "Net Profit"End Sub

Function NetProfit(Gross As Double, Expenses As Double) As Double NetProfit = (Gross - Expenses) * 0.9End Function

'Listing 20.4

Sub TestForSmog2000() Dim intCYear As Integer, strThisCar As StringBadValueLoop: On Error GoTo Bye intCYear = InputBox("Enter the year of your car.", _ "Do I Need a Smog Check?") strThisCar = NeedsSmog(intCYear) If strThisCar = "Yes" Then MsgBox "Your car needs a smog check.", _ vbOKOnly + vbExclamation, "Smog Check 2000" ElseIf strThisCar = "BadValue" Then MsgBox "The year you entered is in the future.", _ vbOKOnly + vbCritical, "Smog Check 2000" GoTo BadValueLoop Else MsgBox "Your car does not need a smog check.", _ vbOKOnly + vbInformation, "Smog Check 2000" End IfBye:End Sub

Function NeedsSmog(CarYear As Integer) As String If CarYear > Year(Now) Then NeedsSmog = "BadValue" ElseIf CarYear


Recommended