逐步调试崩溃VBA

发布于 2025-02-03 04:03:49 字数 1876 浏览 2 评论 0原文

我的宏有问题,然后我想使用逐步进行调试(使用F8),但是当我输入此过程时,我的逐步崩溃了,宏(带有错误)

Option Explicit

Private Sub create_fsm_Cliquer()

    Dim MaFeuille As Worksheet
    Dim nombre_de_vdd As Integer
    Dim nom_fichier_sauvegarde As String
    Dim i As Integer
    Dim j As Integer
    Dim k As Integer
    Dim nb_ligne As Integer
    Dim dernier_rev As String
    Dim word_fichier As Document
    Dim fichier As String
    Dim word_app As Word.Application
    Dim fs As Object
    Dim reponse As Object
    Dim footr As Object
     
    
    Set MaFeuille = Sheets("Info FSM")
    
    dernier_rev = MaFeuille.Cells(5, 2)

    nombre_de_vdd = MaFeuille.Cells(2, 2)

    nb_ligne = Cells.Find("*", [A1], , , , xlPrevious).Row

    fichier = ActiveWorkbook.Path & "\" & "fsm_template_balises.docx"
    
    Set word_app = CreateObject("Word.Application")
    With word_app
        .Visible = True
        .WindowState = 1
    End With
    
    Set word_fichier = word_app.Documents.Open(fichier)

    For i = 14 To nb_ligne
        For Each footr In word_fichier.Sections(1).Footers
            With footr.Range.Find
               .Text = MaFeuille.Cells(i, 1)
               .Replacement.Text = MaFeuille.Cells(i, 2)
               .Execute Replace:=wdReplaceAll
            End With
        Next footr
    Next i

    nom_fichier_sauvegarde = ActiveWorkbook.Path & "\" & "fsm_template_balises_" & dernier_rev & ".docx"

    Set fs = CreateObject("Scripting.FileSystemObject")
    If (fs.FileExists(nom_fichier_sauvegarde)) Then
        reponse = fs.DeleteFile(nom_fichier_sauvegarde, True)
    End If
    word_fichier.SaveAs nom_fichier_sauvegarde

    word_fichier.Close
    word_app.Quit
    
End Sub
    

我的宏崩溃了。到达线 .replacement.text = mafeuille.cells(16,2)

edit:IM使用Excel宏来处理.docx

编辑:结果是我的第一个页脚很好,但其他人是与执行之前一样

i have a problem in my macro then i wanted to debug it using step by step (using F8) but when i enter in this, my step-by-step crashed and the macro finished (with bugs)

Option Explicit

Private Sub create_fsm_Cliquer()

    Dim MaFeuille As Worksheet
    Dim nombre_de_vdd As Integer
    Dim nom_fichier_sauvegarde As String
    Dim i As Integer
    Dim j As Integer
    Dim k As Integer
    Dim nb_ligne As Integer
    Dim dernier_rev As String
    Dim word_fichier As Document
    Dim fichier As String
    Dim word_app As Word.Application
    Dim fs As Object
    Dim reponse As Object
    Dim footr As Object
     
    
    Set MaFeuille = Sheets("Info FSM")
    
    dernier_rev = MaFeuille.Cells(5, 2)

    nombre_de_vdd = MaFeuille.Cells(2, 2)

    nb_ligne = Cells.Find("*", [A1], , , , xlPrevious).Row

    fichier = ActiveWorkbook.Path & "\" & "fsm_template_balises.docx"
    
    Set word_app = CreateObject("Word.Application")
    With word_app
        .Visible = True
        .WindowState = 1
    End With
    
    Set word_fichier = word_app.Documents.Open(fichier)

    For i = 14 To nb_ligne
        For Each footr In word_fichier.Sections(1).Footers
            With footr.Range.Find
               .Text = MaFeuille.Cells(i, 1)
               .Replacement.Text = MaFeuille.Cells(i, 2)
               .Execute Replace:=wdReplaceAll
            End With
        Next footr
    Next i

    nom_fichier_sauvegarde = ActiveWorkbook.Path & "\" & "fsm_template_balises_" & dernier_rev & ".docx"

    Set fs = CreateObject("Scripting.FileSystemObject")
    If (fs.FileExists(nom_fichier_sauvegarde)) Then
        reponse = fs.DeleteFile(nom_fichier_sauvegarde, True)
    End If
    word_fichier.SaveAs nom_fichier_sauvegarde

    word_fichier.Close
    word_app.Quit
    
End Sub
    

My macro crashed when the step-by-step reached the line
.Replacement.Text = MaFeuille.Cells(16, 2)

Edit : im using an excel macro to work on a .docx

Edit : the result is that my first footer is good, but the others are the same as before the execution

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文