Word VBA: преобразование комментариев и имени пользователя в сноски;нужен автор (теперь в сносках), чтобы быть жирным шрифтом - PullRequest
0 голосов
/ 11 июля 2019

Преобразование комментариев и имени пользователя в сноски;нужно, чтобы автор (теперь в сносках) был выделен жирным шрифтом.

Я могу заставить весь текст правильно вводиться, я использую strAuthor, чтобы показать oComment.Author, и это работает для меня.Я просто не могу сделать автора смелым сейчас, когда текст в сносках.Это все еще признает strAuthor;Я пытался объявить rngAuthor как Range, но не смог заставить его жениться на strAuthor.Буду признателен за помощь в настройке rngAuthor.Я смог сделать всю сноску жирным, но мне нужен только автор, чтобы быть жирным.

Я задал похожий вопрос вчера, но я поступил неправильно;Я попросил, чтобы последние 2 слова были выделены жирным шрифтом, и теперь я понимаю, что это может испортить сноски, которые не были преобразованы из комментариев (спасибо Синди за помощь).

Dim oDoc As Document
Dim oComment As Comment
Dim strAuthor As String
Dim rngAuthor As Range
Dim oFootNotes As Footnotes
Dim Ftnote As Footnote
Dim rngFootnote As Word.Range

'Document is the ActiveDocument
Set oDoc = Application.ActiveDocument

'find comment
For Each oComment In ActiveDocument.Comments

Set rngAuthor = oComment.Scope.Editors

'Comment made by "Author"
  strAuthor = oComment.Author

  'create a footnote and move comment text to footnote with rngAuthor(bold)
  oDoc.oFootNotes.Add Range:=oComment.Scope, Text:=oComment.Range.Text, Text:=oComment.Range.Editors
  rngAuthor.Font.bold = True
  ActiveWindow.ActivePane.View.SeekView = wdSeekFootnotes
  'Delete Comment
  oComment.Delete

Next

Когда я бегу по кодуЯ получаю ошибку времени выполнения: 13 для Set rngAuthor = oComment.Scope.Editors и ошибку времени выполнения 438 для oDoc.oFootNotes.Add Range:=oComment.Scope, Text:=oComment.Range.Text, Text:=oComment.Range.Editors

1 Ответ

1 голос
/ 17 июля 2019

Объявление диапазона сноски позволяет управлять диапазоном, чтобы комментарий можно было добавить в сноску, а затем, при объявлении автора комментария в виде строки, имя автора можно применить к диапазону сноски в виде текста: "rngFootnote.Text = strAuthor "и это, в свою очередь, означает, что имя автора может быть выделено жирным шрифтом с помощью" rngFootnote.Font.bold = True ".Существует также код, так что, если имя автора отображается как «фамилия, имя», оно будет преобразовано в «фамилию имени».

Dim oDoc As Document
Dim oComment As Comment
Dim strAuthor As String
Dim strForename As String
Dim strSurname As String
Dim oFootnotes As Footnotes
Dim Ftnote As Footnote
Dim rngFootnote As Word.Range

'Document is the ActiveDocument
Set oDoc = Application.ActiveDocument
Set oFootnotes = oDoc.Footnotes

'find comment
For Each oComment In ActiveDocument.Comments

  'Comment made by "Author"
  strAuthor = oComment.Author

  'create a footnote and move comment text to footnote with Author
  oDoc.Footnotes.Add Range:=oComment.Scope, Text:=oComment.Range.Text & "  "

  'the author's name now needs to be bold (now the last two words in each footnote)
  For Each Ftnote In oFootnotes               'this adds the new footnote with the comment
    Set rngFootnote = Ftnote.Range            'this is where the comment is added

    rngFootnote.Collapse wdCollapseEnd

    If InStr(strAuthor, ",") > 0 Then       'name added
      'split surname from strUserName
      strSurname = Split(strAuthor, " ")(0)
        'delete comma
        strSurname = Trim(Left(strSurname, Len(strSurname) - 1))
      'split forename from strUserName
      strForename = Right(strAuthor, Len(strAuthor) - InStrRev(strAuthor, ","))
      strForename = Trim(Right(strForename, Len(strForename) - 1))
      strAuthor = strForename & " " & strSurname
    ElseIf InStr(strAuthor, "") > 0 Then       'name added
    End If
  Next
    rngFootnote.Text = strAuthor
    rngFootnote.Font.bold = True
  'Delete comment
  oComment.Delete
Next
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...