Tìm và thay thế trong VBA Word

phuc anh

Yêu THVBA
Chào mọi người.
Mình đang lúng túng trong việc chuyển Mathtype sang latex bằng code VBA, hiện đang vướng phải vấn đề sau:
Chuyển $.........$ thành [latex]..........[/latex]
VD: $-\frac{3}{8}$ thành [latex]-\frac{3}{8}[/latex]

Mong được trợ giúp.
Cảm ơn!
 

phuonghong1997

Yêu THVBA như điếu đổ
Chắc là đang muốn chuyển dữ liệu word lên web nào đó rồi.
Mình nhận giúp nếu bạn ủng hộ diễn đàn số tiền 100k.
Thông tin ủng hộ diễn đàn:
Tài khoản Ngân hàng thương mại cổ phần Ngoại thương Việt Nam Vietcombank, số tài khoản: 0011003264055
Chi nhánh Quận Hoàn Kiếm, Hà Nội.
Chủ tài khoản: Phạm Minh Hoàng.


Hoặc bạn có thể tham khảo khóa học VBA Word cơ bản ở đây:
 
Chào mọi người.
Mình đang lúng túng trong việc chuyển Mathtype sang latex bằng code VBA, hiện đang vướng phải vấn đề sau:
Chuyển $.........$ thành [latex]..........[/latex]
VD: $-\frac{3}{8}$ thành [latex]-\frac{3}{8}[/latex]

Mong được trợ giúp.
Cảm ơn!
Mã:
Sub doisthanhlatex()

    Selection.Find.ClearFormatting

    Selection.Find.Replacement.ClearFormatting

    With Selection.Find

        .text = "($)(*)($)"

        .Replacement.text = "\1#\2\3##"

        .Forward = True

        .Wrap = wdFindContinue

        .Format = False

        .MatchCase = False

        .MatchWholeWord = False

        .MatchAllWordForms = False

        .MatchSoundsLike = False

        .MatchWildcards = True

    End With

    Selection.Find.Execute Replace:=wdReplaceAll

    Selection.Find.ClearFormatting

    Selection.Find.Replacement.ClearFormatting

    With Selection.Find

        .text = "$##"

        .Replacement.text = "[/latex]"

        .Forward = True

        .Wrap = wdFindContinue

        .Format = False

        .MatchCase = False

        .MatchWholeWord = False

        .MatchWildcards = False

        .MatchSoundsLike = False

        .MatchAllWordForms = False

    End With

    Selection.Find.Execute Replace:=wdReplaceAll

    Selection.Find.ClearFormatting

    Selection.Find.Replacement.ClearFormatting

    With Selection.Find

        .text = "$#"

        .Replacement.text = "[latex]"

        .Forward = True

        .Wrap = wdFindContinue

        .Format = False

        .MatchCase = False

        .MatchWholeWord = False

        .MatchWildcards = False

        .MatchSoundsLike = False

        .MatchAllWordForms = False

    End With

    Selection.Find.Execute Replace:=wdReplaceAll

End Sub
 
Nếu là học viên của thì người ta không cần replace hai lần như trên, mà chỉ làm một lần thôi ạ.
Mã:
Sub Macro1()
'
' Macro1 Macro
'
'
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .text = "($)(*)($)"
        .Replacement.text = "^91latex^93\2^91/latex^93"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchFuzzy = False
        .MatchWildcards = True
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
End Sub
 
Top