将不同工作表的串联的特定部分用斜体显示

时间:2017-02-18 22:20:58

标签: excel vba excel-vba

我刚刚开始尝试使用VBA,并希望创建一个代码,在连接中使用斜体显示演示文稿的标题,因为Excel通常不允许这种情况发生。我还想将输出粘贴到另一个工作表中。

我创建的当前代码是将连接输出粘贴到SAME工作表的一个特定列中(名为"演示表"),但我无法弄清楚如何:

  1. 从同一工作簿中的第一行和第一行开始,将连接的输出粘贴到不同工作表(名为"演示文稿被引用")的特定列中

  2. 如何让它自动斜体化标题列中的文本。连接中的所有其他文本不应为斜体。

  3. 我将不胜感激任何帮助!

    表格结构: enter image description here

    当前输出: enter image description here

    Worksheets("Presentations Table").Range("a3", Worksheets("Presentations Table").Range("a3").End(xlDown)).Select
    Row = 1
    col = 1
    For Each Cell In Selection
    Authors = Cells(Row, col)
    Year_Month = Cells(Row, col + 1)
    Title = Cells(Row, col + 2)
    Presentation_Type = Cells(Row, col + 3)
    Event_Name = Cells(Row, col + 4)
    Location = Cells(Row, col + 5)
    
    Worksheets("Presentations Table").Cells(Row, col + 2) = Authors & " (" & Year_Month & "). " & Title & ". " & Presentation_Type & " at the " & Event_Name & ", " & Location & "."
    
    Row = Row + 1
    Next
    

1 个答案:

答案 0 :(得分:1)

您可以将它们粘贴为HTML格式,如下所示(未经测试):

Dim c As Range, s As String    
Set c = ThisWorkbook.Worksheets("Presentations Table").Cells(3)

s = "<html>"
While c <> ""
    s = s & c & " (" & c(, 2) & "). <i>" & c(, 3) & "</i>. " & c(, 4) & " at the " & c(, 5) & ", " & c(, 6) & ".</br>"
    set c = c(2) ' the cell below c
Wend

With CreateObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
    .SetText s
    .PutInClipboard
End With

c(2).PasteSpecial    
相关问题