0
我有下面的代碼,位於窗體上的按鈕上的OnClick事件。該代碼執行以下操作:VBA代碼出錯462
在子窗體Forms! FrmFScomposition! PRODUCAO! [Prod_Cena_Guiao](帶有一個OLE對象)我有一個單詞文檔列表,這個列表是在一個組合框的幫助下更新的。該代碼爲所有文檔創建一個Loop並將它們複製到另一個子窗體Forms! FrmFScomposition! SubfrmKitCenas! [FSKitCenasOLE],這些文件都在一個。代碼工作正常,即使您重複加載SAME數據的過程。但是當我在組合框中選擇另一組文本時,第一次嘗試操作時出現錯誤462,但是當我再次嘗試時,代碼再次運行。我厭倦了嘗試不同的可能性,但我找不到解決方案。有人可以幫助我或指出我錯過的東西嗎?下面我會發布我正在使用的兩個子。提前感謝您的關注。
代碼上按鈕:
Private Sub Command54_Click()
Call DoResetKit
Dim FirstTime As Integer
FirstTime = 1
Me.FirstTimeBox = FirstTime
Forms!frmFScomposicao!PRODUCAO.SetFocus
DoCmd.RunCommand acCmdRecordsGoToFirst
For f = 1 To Forms!frmFScomposicao!PRODUCAO![tiroliro]
Call CompilarKitDiaGravacao
DoCmd.RunCommand acCmdRecordsGoToNext
Next f
DoCmd.RunCommand acCmdRecordsGoToFirst
End Sub
代碼上第一UDF
Public Sub CompilarKitDiaGravacao()
Dim CenasParaRecolha As Object
Dim DocumentoDestino As Object
Set CenasParaRecolha = Forms!frmFScomposicao!PRODUCAO![Prod_Cena_Guiao].Object.Application.WordBasic
Forms!frmFScomposicao!PRODUCAO![Prod_Cena_Guiao].Action = acOLEActivate
With CenasParaRecolha
Selection.WholeStory
Selection.Copy
End With
Set CenasParaRecolha = Nothing
If Forms!frmFScomposicao.FirstTimeBox = 1 Then
' Forms!frmFScomposicao!subfrmKitCenas![FSKitCenasOLE].Action = acOLEPaste
Set DocumentoDestino = Forms!frmFScomposicao!subfrmKitCenas![FSKitCenasOLE].Object.Application.WordBasic
Forms!frmFScomposicao!subfrmKitCenas![FSKitCenasOLE].Action = acOLEActivate
With DocumentoDestino
'Selection.WholeStory
'Selection.Delete
Selection.EndKey wdStory
Selection.InsertBreak Type:=wdSectionBreakContinuous
Selection.PasteAndFormat wdPasteDefault
End With
Set DocumentoDestino = Nothing
Forms!frmFScomposicao!FirstTimeBox = Forms!frmFScomposicao!FirstTimeBox + 1
Else
Set DocumentoDestino = Forms!frmFScomposicao!subfrmKitCenas![FSKitCenasOLE].Object.Application.WordBasic
Forms!frmFScomposicao!subfrmKitCenas![FSKitCenasOLE].Action = acOLEActivate
With DocumentoDestino
Selection.EndKey wdStory
Selection.InsertBreak 'Type:=wdSectionBreakContinuous
Selection.PasteAndFormat wdPasteDefault
End With
Set DocumentoDestino = Nothing
Forms!frmFScomposicao!FirstTimeBox = Forms!frmFScomposicao!FirstTimeBox + 1
End If
'Set CenasParaRecolha = Nothing
'Set DocumentoDestino = Nothing
End Sub
代碼上第二UDF
Public Sub DoResetKit()
Dim ResetKit As Object
Set ResetKit = Forms!frmFScomposicao!subfrmKitCenas![FSKitCenasOLE].Object.Application.WordBasic
Forms!frmFScomposicao!subfrmKitCenas![FSKitCenasOLE].Action = acOLEActivate
With ResetKit.Selection
Selection.WholeStory
Selection.Delete
End With
Set ResetKit = Nothing
End Sub
隨着ResetKit.Selection Selection.WholeStory ------這是該行強調,但如果我重新運行,代碼作品agaiñ Selection.Delete End With – Armando
您的'With'塊沒有使用捕獲的引用。 – Comintern
@Comintern試圖告訴你什麼'帶有ResetKit.Selection Selection.WholeStory Selection.Delete End With'是不必要的。你的兩行內容應該是'.WholeStory'和'.Delete' – FreeMan