Option Explicit
Sub 選擇類型訊息()
Dim Msg1, Msg2
Select Case Selection.Type
Case 1
Msg1 = "位置"
Msg2 = "圖形或文字方塊"
Case 2
Msg1 = "文字列"
Msg2 = "表的行或列"
Case 4, 5
Msg1 = "表的行或列"
Msg2 = "位置"
Case 8
Msg1 = "圖形或文字方塊"
Msg2 = "文字列"
Case Else
Msg1 = "文件中沒有的項目"
Msg2 = "你的最愛"
End Select
MsgBox "目前所選擇的是「" & Msg1 & "」!" _
& vbCr & "請選擇「" & Msg2 & "」!" _
, vbInformation + vbOKCancel, "選擇類型訊息"
End Sub
Sub 表格所在的位置是() '表格用!錄自Word VBA Lesson 17您現在所在的位置是
Dim MsgTitle, thisR, thisC 'row, column
MsgTitle = "您現在所在的位置是"
With Selection
thisR = .Information(wdStartOfRangeRowNumber)
thisC = .Information(wdStartOfRangeColumnNumber)
End With
If thisR = -1 Then
MsgBox "游標並不在表中", vbInformation _
, MsgTitle
Else
MsgBox "第" & thisR & "列" & vbCr & "第" & thisC & "欄", _
vbInformation, MsgTitle
End If
End Sub
Sub 所在位置標題() 'Alt+Z
Dim a As Paragraph, t As String, tn As String, cl As Boolean, rng As Range
On Error GoTo ErrH:
If Selection.Information(wdInFootnote) Then ActiveWindow.Panes(1).Close: cl = True '如果插入點在註腳視窗中
Set a = Selection.Paragraphs(1)
tn = a.Style
Set rng = a.Range
Do Until a.Style = "標題 1"
Set a = a.Previous
If Left(a.Style, 2) = "標題" And Right(tn, 1) > Right(a.Style, 1) Then 'Exit Do
rng.SetRange a.Range.Characters(2).Start, a.Range.Characters(a.Range.Characters.Count - 1).End
If a.Range.Characters(1) <> "頁" And Not IsNumeric(rng) Then
t = a.Style & " : " & a.Range & vbCr & Space(Right(a.Style, 1) * 2) & t
tn = a.Style
End If
End If
Loop 'a.Range會包括段落字元,要去除可用:Left(a.Range, Len(a.Range) - 1)
MsgBox ActiveDocument.path & vbCr & vbCr & "目前標題為:" & vbCr & vbCr & t & _
vbCr & vbCr & vbCr & "目前頁碼:" & Selection.Information(wdActiveEndAdjustedPageNumber), _
vbInformation
If cl Then '如果插入點原在註腳視窗中
'
' 巨集7 巨集
' 巨集錄製於 2011/6/23,錄製者 Oscar Sun
'
If ActiveWindow.ActivePane.View.Type = wdPrintView Or ActiveWindow. _
ActivePane.View.Type = wdWebView Or ActiveWindow.ActivePane.View.Type = _
wdPrintPreview Then
ActiveWindow.View.SeekView = wdSeekFootnotes
Else
ActiveWindow.View.SplitSpecial = wdPaneFootnotes
End If
End If
Exit Sub
ErrH:
Select Case Err.Number
Case 91 '沒有設定物件變數或 With 區塊變數
MsgBox "本文件沒有標題樣式!", vbExclamation
End Select
End Sub