gpt4 book ai didi

excel - 如何不保留最后一项复制?

转载 作者:行者123 更新时间:2023-12-04 21:28:32 25 4
gpt4 key购买 nike

我正在使用 Excel VBA 创建 Word 文档并添加图像。
由于我希望图像适合页面宽度的一半,因此我创建了一个具有两列布局的临时文档,并先将图像粘贴到那里,然后将其剪切并粘贴到我真正需要的文档中。
临时文档在使用后关闭。当程序关闭主文档并创建另一个文档时,会弹出一个窗口询问我是否要保留最后一个项目的复制。如何从 VBA 关闭此窗口或对它说“不”?
话虽如此,程序继续运行,并忽略弹出窗口,但当我明确表示时,程序没有关闭很烦人。
创建所有文档后,Microsoft Word 的许多窗口保持打开状态,每个窗口都会弹出此窗口。我想它也会在内存中保存图像,所以这也不好。

Sub Newdoc_withImages()

Dim wdapp As Word.Application
Dim doct As Documents
Dim imag As Variant
.
.
*more variables*

Set wdapp = New Word.Application
With wdapp
.Visible = True
.Activate
.Documents.Add "C:\Users\USER\Desktop\Template.dot"
.Selection.GoTo (*I position the cursor and write some things in preparation to add image*)
If condition (*are there any images available? If yes create Temporal Document and give two columns layout for it*)
.Documents.Add
.Documents(1).PageSetup.TextColumns.Add Width:=InchesToPoints(2.85), EvenlySpaced:=True
For Each imag In imgcollection
If condition (*If True, take the image and paste it in the Temporal Doc, then cut it to paste it in the document created at the beginning*)
.Documents(1).Select
.Documents(1).InlineShapes.AddPicture Filename:=imag, LinkToFile:=False, SaveWithDocument:=True
.Documents(1).InlineShapes(1).Select
.Selection.Cut
.Documents(2).Select
.Selection.GoTo (*Position to paste the img*)
.Selection.Paste
imgcollection.Remove (imag) (*here I remove the image from my collection, not relevant*)
End If
Next imag
(*The Temporal Document actually closes*)
.Documents(1).Close 0
(*I return to the Document I actually care, ready for the next batch of images if I need to add more for given condition*)
.ActiveDocument.Select
End If
.DisplayAlerts = 0 (*I tried these to close any pop up maybe I'm wrong, because It doesn't seem to work either*)
.ActiveDocument.SaveAs2 (objSubFolder.Path & "\" & StrConv(NamesxCrear.Items(i), vbProperCase))
.ActiveDocument.Close (*HERE is where the pop up window comes up asking me if I want to keep the last item copied, I don't know how to close it from here*)
.Application.Quit (*doesn't actually quit, program reamins open because of the pop up*)

End With

End Sub
这是弹出窗口的样子:
This is what the pop up looks like

最佳答案

每当您完成复制到剪贴板的内容时,您应该发出以下命令:

Application.CutCopyMode = False
在处理图片等大型对象时,这一点尤其重要。把它放在你的 .Paste 之后命令。

关于excel - 如何不保留最后一项复制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62882446/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com