我是社區和編程的新手。我主要是涉獵和使用網絡蠻力完成我所需要的。我試圖通過將類似例程整合到一個函數中來清理一些代碼(類似於詳細的流程here)。但是我不知如何開始。現在編寫的代碼會一遍又一遍地在文檔的末尾插入不同的表單。創建函數或公共子文件
Sub InsertQA17()
If ActiveDocument.Bookmarks.Exists("\EndOfDoc") = True Then
ActiveDocument.Bookmarks("\EndOfDoc").Select
Selection.Collapse Direction:=wdCollapseEnd
Selection.Range.InsertBreak (wdSectionBreakNextPage)
Selection.PageSetup.Orientation = wdOrientPortrait
Selection.Style.ParagraphFormat.SpaceAfter = 0
Selection.Style.ParagraphFormat.SpaceBefore = 0
'OQE Form below needs to be changed to reflect the sub called
Selection.InsertFile FileName:=OQEPath & _
"\QA17.doc", Range:="", ConfirmConversions:=False, Link:=False, Attachment:=False
UpdateThisFormsFields
Else
MsgBox "Bookmark ""\EndOfDoc"" does not exist!"
End If
End Sub
Sub InsertWELDRECORD()
If ActiveDocument.Bookmarks.Exists("\EndOfDoc") = True Then
ActiveDocument.Bookmarks("\EndOfDoc").Select
Selection.Collapse Direction:=wdCollapseEnd
Selection.Range.InsertBreak (wdSectionBreakNextPage)
Selection.PageSetup.Orientation = wdOrientLandscape
Selection.Style.ParagraphFormat.SpaceAfter = 0
Selection.Style.ParagraphFormat.SpaceBefore = 0
'OQE Form below needs to be changed to reflect the sub called
Selection.InsertFile FileName:=OQEPath & _
"\WELDRECORD.doc", Range:="", ConfirmConversions:=False, Link:=False, Attachment:=False
UpdateThisFormsFields
Else
MsgBox "Bookmark ""\EndOfDoc"" does not exist!"
End If
End Sub
我想我要清理的代碼是 1,裏面的代碼接收傳遞給它的變量當色帶按鈕被按下的肉的功能。 2.基於變量a調用函數,在文檔末尾完成插入。
我看到的問題: 1.我將代碼重複一遍又一遍地重複使用〜50個形式(暴力方法)。 2.一些文件是肖像和一些風景。 (我認爲這可以是一個變量。) 3.雖然我理解函數的概念(我多次閱讀鏈接),但我不知道如何開始。我知道這應該很容易。
再次,我正在學習,所以請溫柔。如果你必須送我正確的方向。
謝謝 蘭迪
非常感謝。我現在正在消化這些代碼,以確保我完全理解它並從中學到一些東西。 – RandyB
爲什麼.paragraphs.spacebefore和.spaceafter不影響傳入文件,因爲它用於?我的方法從傳入的文件中刪除了段落格式。這是從選擇變爲範圍的結果嗎?如果有,是否有辦法保留這種能力? – RandyB