Vba 将Whatsapp.txt文件转换为原始Whatsapp格式

Vba 将Whatsapp.txt文件转换为原始Whatsapp格式,vba,ms-word,Vba,Ms Word,我有.txt文件格式的whatsapp聊天。我希望它转换为原始whatsapp格式(即whatsapp原始接口)。 输入是.txt文件 例如: 12/11/2014, 12:22 PM - John: Hi Stacy 12/11/2014, 12:22 PM - John: :) 13/11/2014, 2:59 AM - John: How are you? 13/11/2014, 2:59 AM - John: Are u home? 13/11/2014, 8:09 AM - Stacy

我有.txt文件格式的whatsapp聊天。我希望它转换为原始whatsapp格式(即whatsapp原始接口)。 输入是.txt文件

例如:

12/11/2014, 12:22 PM - John: Hi Stacy
12/11/2014, 12:22 PM - John: :)
13/11/2014, 2:59 AM - John: How are you?
13/11/2014, 2:59 AM - John: Are u home?
13/11/2014, 8:09 AM - Stacy: Hi John
13/11/2014, 8:10 AM - Stacy: yeah I am good
13/11/2014, 8:10 AM - Stacy: and home too
13/11/2014, 9:14 PM - John: ok
16/11/2014, 4:14 PM - Stacy: how are you?
16/11/2014, 4:16 PM - John: I am good too
16/11/2014, 4:16 PM - John: See u tmrw at work
16/11/2014, 4:16 PM - John: :)
16/11/2014, 4:24 PM - Stacy: yeah ok
现在,我希望输出在Word文档中,具有与whatsapp类似的接口

[也就是说,约翰的所有谈话都在左边,斯泰西的所有谈话都在右边]

我尝试将这个.txt文件导入excel,然后在word中编辑。但那没用

所需的输出格式:

(与whatsapp格式非常相似)

我就是这么做的:

1) 我从.txt文件导入了excel中的数据

2) 我使用python代码将txt格式转换为excel文件

3) 然后我将其复制到.doc文件并添加了边框

4) 现在我删除了输出边框。这就是我在第一个链接中附加的格式

我面临的问题是,无论文本在哪里,我都需要手动转到该单元格并选择“无边框”。我有1000个这样的

我是否可以通过编程方式实现这一点


使用Word或Excel VBA可以做些什么吗?

如果您已经有了如图所示的表,您可以做的是删除所有Board并运行以下代码

Sub demo1()
With ActiveDocument.Range
Dim oCell As Cell
Dim oRow As Row
'remove all boarders before executing this code
    For Each oRow In .Tables(1).Rows
        For Each oCell In oRow.Cells
            If Not oCell.Range.Text = Chr(13) & Chr(7) Then
                Set rng = oCell.Range
                With rng
                    With .Borders(wdBorderTop)
                        .LineStyle = Options.DefaultBorderLineStyle
                        .LineWidth = Options.DefaultBorderLineWidth
                        .Color = Options.DefaultBorderColor
                    End With
                    With .Borders(wdBorderLeft)
                        .LineStyle = Options.DefaultBorderLineStyle
                        .LineWidth = Options.DefaultBorderLineWidth
                        .Color = Options.DefaultBorderColor
                    End With
                    With .Borders(wdBorderBottom)
                        .LineStyle = Options.DefaultBorderLineStyle
                        .LineWidth = Options.DefaultBorderLineWidth
                        .Color = Options.DefaultBorderColor
                    End With
                    With .Borders(wdBorderRight)
                        .LineStyle = Options.DefaultBorderLineStyle
                        .LineWidth = Options.DefaultBorderLineWidth
                        .Color = Options.DefaultBorderColor
                    End With
                End With
            End If
        Next oCell
    Next oRow
End With
End Sub

如果您已经有了如图所示的表,您可以做的是删除所有boarder并运行以下代码

Sub demo1()
With ActiveDocument.Range
Dim oCell As Cell
Dim oRow As Row
'remove all boarders before executing this code
    For Each oRow In .Tables(1).Rows
        For Each oCell In oRow.Cells
            If Not oCell.Range.Text = Chr(13) & Chr(7) Then
                Set rng = oCell.Range
                With rng
                    With .Borders(wdBorderTop)
                        .LineStyle = Options.DefaultBorderLineStyle
                        .LineWidth = Options.DefaultBorderLineWidth
                        .Color = Options.DefaultBorderColor
                    End With
                    With .Borders(wdBorderLeft)
                        .LineStyle = Options.DefaultBorderLineStyle
                        .LineWidth = Options.DefaultBorderLineWidth
                        .Color = Options.DefaultBorderColor
                    End With
                    With .Borders(wdBorderBottom)
                        .LineStyle = Options.DefaultBorderLineStyle
                        .LineWidth = Options.DefaultBorderLineWidth
                        .Color = Options.DefaultBorderColor
                    End With
                    With .Borders(wdBorderRight)
                        .LineStyle = Options.DefaultBorderLineStyle
                        .LineWidth = Options.DefaultBorderLineWidth
                        .Color = Options.DefaultBorderColor
                    End With
                End With
            End If
        Next oCell
    Next oRow
End With
End Sub

欢迎来到StackOverflow。请花点时间阅读关于如何提问的指南。你需要缩小你的问题范围,展示你尝试过的代码,并描述这些代码是如何不起作用的。@Cindy Meister:请参阅编辑请将其格式化以使其可读-你需要帮助,你就完成了工作…我认为Java标记不适合这里。另外,我认为你可能只关注一种语言,因为我们不能完全按照你想要的方式来做这项工作。运行VBA代码时出现了什么异常?什么是失败的?阅读代码中的目标表在哪里?欢迎使用StackOverflow。请花点时间阅读关于如何提问的指南。你需要缩小你的问题范围,展示你尝试过的代码,并描述这些代码是如何不起作用的。@Cindy Meister:请参阅编辑请将其格式化以使其可读-你需要帮助,你就完成了工作…我认为Java标记不适合这里。另外,我认为你可能只关注一种语言,因为我们不能完全按照你想要的方式来做这项工作。运行VBA代码时出现了什么异常?什么是失败的?阅读代码中目标表的位置可能很有用?Hai Rahul。这不是确切的o/p,但我从您的代码中得到了想法,我想我可以使用您的代码继续fwd。非常感谢:)在这样的情况下,很少有人能够理解你想要什么。你必须围绕他们提供的解决方案工作。Hai Rahul。这不是确切的o/p,但我从您的代码中得到了想法,我想我可以使用您的代码继续fwd。非常感谢:)在这样的情况下,很少有人能够理解你想要什么。您必须围绕他们提供的解决方案开展工作。