列表要复制到另一个表格并生成PDF
我有一个列表,必须在另一个工作表中的每一行中复制日期,并将其保存为PDF
数据在“指令”选项卡中的每一行中,需要在“移动策略”中复制并保存为pdf
以下是每行需要复制的地方,并保存为pdf
我尝试了以下代码,但是它确实可以正常工作,并且创建空白的PDF和第一行永远不会生成。有人可以帮我解决这个问题,以便它可以顺利
Sub ARSOAPDF()
Dim varItemsToReplace As Variant
Dim varItem As Variant
Dim wksSource As Worksheet
Dim wksDest As Worksheet
Dim rngSource As Range
Dim rngSource2 As Range
Dim rngCell As Range
Dim email_ As String
Dim email2_ As String
Dim cc As String
Dim subject_ As String
Dim path_ As String
Path1 = Worksheets("Instruction").Range("G1").Value
Set wksSource = Worksheets("Instruction")
Set wksDest = Worksheets("Mobile Policy")
wksSource.Activate
email_ = cell.Offset(1, 0).Value
email2_ = cell.Offset(1, 1).Value
cc = cell.Offset(1, 2).Value
subject_ = cell.Offset(1, 3).Value
path_ = cell.Offset(1, 4).Value
With wksSource
Set rngSource = .Range("A2:A" & .Cells(.Rows.Count, "A").End(xlUp).Row)
End With
For Each rngCell In rngSource
With wksDest
Range("A75").Formula = email_
Range("C75").Formula = email2_
Range("E75").Formula = cc
Range("G75").Formula = subject_
Range("A1").Select
wksDest.Activate
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
path1 & ActiveSheet.Range("C2").Value & " - " & ActiveSheet.Range("B2").Value & ".pdf" _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=False
ActiveWorkbook.Close SaveChanges:=False
End With
Next rngCell
运行
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您未正确使用。在每行之前添加一个点。因此
range(“ A75”)。公式=电子邮件_
应该是.range(“ A75”)。公式=电子邮件_
它在第二和更多循环中工作,因为您有
wksdest.activate
在循环末端,因此第一个循环将读取ActivesHeet,而不是wksdest
。在第二个循环中,因为wksdest
是ActiveOne,所以它可以工作。可能您需要
ActiveWorkBook.Close Savechanges:= false
在循环外或删除。You are not using
With
properly. Add a dot before each line. SoRange("A75").Formula = email_
should be.Range("A75").Formula = email_
It works in second and more loops because you have
wksDest.Activate
at the end of the loop, so the first loop will read the Activesheet, notwksDest
. At second loop, becausewksDest
is the activeone, then it works.And probably you'll need
ActiveWorkbook.Close SaveChanges:=False
outside the loop or deleted.