VBA Error 4198 “Runtime Error” With Paste

≡放荡痞女 提交于 2019-12-11 00:37:03

问题


I have been trying to write a word VBA script that uses a screenshot (already copied to the clipboard) and pastes it into a word document to be formatted and saved. The program works great on my computer at work, but when I distributed it to others, it failed to work on about 25% of the computers. The error that I received was "4198 Runtime Error". I have searched for similar problems that other people have had, but I am still at a loss. All of the computers in the office run the same version of work, 2010 standard version.

The issue is with the very last line of code, selection.paste. I did make sure that they had a screenshot on their clipboard before running the script.

Thank you so much for any and all input.

Sub MapMaker()

'set up new document with narrow margins and landscape orientation
With Selection.PageSetup
    .LineNumbering.Active = False
    .Orientation = wdOrientPortrait
    .TopMargin = InchesToPoints(0.5)
    .BottomMargin = InchesToPoints(0.5)
    .LeftMargin = InchesToPoints(0.5)
    .RightMargin = InchesToPoints(0.5)
    .Gutter = InchesToPoints(0)
    .HeaderDistance = InchesToPoints(0.5)
    .FooterDistance = InchesToPoints(0.5)
    .PageWidth = InchesToPoints(8.5)
    .PageHeight = InchesToPoints(11)
    .FirstPageTray = wdPrinterDefaultBin
    .OtherPagesTray = wdPrinterDefaultBin
    .SectionStart = wdSectionNewPage
    .OddAndEvenPagesHeaderFooter = False
    .DifferentFirstPageHeaderFooter = False
    .VerticalAlignment = wdAlignVerticalTop
    .SuppressEndnotes = False
    .MirrorMargins = False
    .TwoPagesOnOne = False
    .BookFoldPrinting = False
    .BookFoldRevPrinting = False
    .BookFoldPrintingSheets = 1
    .GutterPos = wdGutterPosLeft
End With
If Selection.PageSetup.Orientation = wdOrientPortrait Then
    Selection.PageSetup.Orientation = wdOrientLandscape
Else
    Selection.PageSetup.Orientation = wdOrientPortrait
End If
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

'paste and resize screenshot to full page width
Selection.Paste

回答1:


4198 Runtime Error might associate with links. If you have links on your origin word document where it is being printscreened, try remove it and see if that solve the problem.



来源:https://stackoverflow.com/questions/25247849/vba-error-4198-runtime-error-with-paste

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!