如何修改此 VBVB 的代码

How to modify this VBA code for VB

我正在使用此 VB将文本框文本转换为常规文本的代码。但是它通过 shp.TypesString = Left(shp.TextFrame.TextRange.Text, _ shp.TextFrame.TextRange.Characters.Count - 1) 上的错误,而我在 VB.

中编译

我应该在 VB 的代码中更改什么?

这是VB一个代码:

Sub ConvertTextBoxToText()
    Dim shp As Shape
    Dim oRngAnchor As Range
    Dim sString As String

    For Each shp In ActiveDocument.Shapes

        If shp.Type = msoTextBox Then
            ' copy text to string, without last paragraph mark
            sString = Left(shp.TextFrame.TextRange.Text, _
                    shp.TextFrame.TextRange.Characters.Count - 1)

            If Len(sString) > 0 Then
                ' set the range to insert the text
                Set oRngAnchor = shp.Anchor.Paragraphs(1).Range
                ' insert the textbox text before the range object
                oRngAnchor.InsertBefore sString
            End If

            shp.Delete

        End If

    Next shp

    'Strip out beginning and ending textbox markers
    Selection.HomeKey unit:=wdStory
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting

    With Selection.Find
        .Text = "Textbox start << "
        .Replacement.Text = ""
        .Forward = True
        ' .Wrap = wdFindContinue
        .Format = False
        .MatchCase = True
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With

    Selection.Find.Execute Replace:=wdReplaceAll

    With Selection.Find
        .Text = ">> Textbox end"
        .Replacement.Text = ""
        .Forward = True
        .wrap = wdFindContinue
        .Format = False
        .MatchCase = True
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
End Sub

VB 代码:?

可以吗?

VB 使用 VBA 作为它的语言。所以不需要转换。 VB 是托管 VBA 的应用程序对象和表单包,就像 Word 是托管 VBA 的文字处理器一样。

在您的代码中,您没有连接到 Word。在 Word 中,某些对象自动可用。在 Word 之外,您必须连接到它们。

Set xlBook = GetObject("C:\Users\User\Documents\Super.xls")
For each wsheet in xlbook.worksheets
    msgbox wsheet.name
    wsheet.printOut 
next

set xlapp = createobject("Excel.Application")
xlapp.Workbooks.Open "C:\Users\User\Documents\Super.xls"
'43 is 95/97 look up xlExcel9795 in object browser to see other options
xlapp.ActiveWorkbook.SaveAs "C:\Users\User\Documents\Super.xls", 43

Set GetExcelApp = GetObject("", "Excel.Application")
Msgbox GetExcelApp