excel - 将值从一个工作簿复制到新创建的工作簿
问题描述
有人可以在下面查看我的代码并告诉我缺少什么吗?我认为这会起作用,但一直在复制功能上中断。非常感谢帮助。
代码复制一个 excel 工作簿模板并在新目录中重命名它。然后需要将当前工作簿中的数据粘贴到新工作簿中。从此工作簿表“站点页面”复制,并粘贴到 NewFileName 表“摘要”中。
Public NewIntegration As String
Sub Copy_One_File()
'Variables
Dim TemplateWorkbook As String
Dim NewWorkbook As String
Dim GivenLocation As String
Dim OldFileName As String
Dim NewFileName As String
'Define Strings
TemplateWorkbook = "\\r.sharepoint.com@SSL\DavWWWRoot\teams\NOE-RadioEng\Radio\New Build\_2019 NSB Tracker\Integration Reports\Template\TEMPLATE.xlsx"
NewWorkbook = "\\r.sharepoint.com@SSL\DavWWWRoot\teams\NOE-RadioEng\Radio\New Build\_2019 NSB Tracker\Integration Reports\TEMPLATENew.xlsx"
GivenLocation = "\\r.sharepoint.com@SSL\DavWWWRoot\teams\NOE-RadioEng\Radio\New Build\_2019 NSB Tracker\Integration Reports\"
ReportCreator = "\\r.sharepoint.com@SSL\DavWWWRoot\teams\NOE-RadioEng\Radio\New Build\_2019 NSB Tracker\Site_Integration_Report_Creator.xlsm"
OldFileName = "TEMPLATENew.xlsx"
NewFileName = Range("D9").Text 'grab new file name report creator
NewIntegration = GivenLocation & NewFileName 'New location and file name
'Functions
FileCopy TemplateWorkbook, NewWorkbook 'copy file to new location
Name GivenLocation & OldFileName As GivenLocation & NewFileName 'Rename based on H2 cell name
'MsgBox NewIntegration
'Workbooks.Open (NewIntegration)
'MsgBox NewIntegration
'Workbook.Close (NewIntegration)
'MsgBox Worksheets("Summary").Range("A1")
'copy values to new sheet
Worksheets("Site Page").Range("J2").Copy_ Workbooks(NewIntegration).Worksheets("Summary").Range("G1")
End Sub
解决方案
你可以尝试这样的事情:
Dim wbNew As Workbook
'...
'...
Set wbNew = Workbooks.Open(NewIntegration, ReadOnly:=False)
'what is the source of the copy operation???
Worksheets("Site Page").Range("J2").Copy wbNew.Worksheets("Summary").Range("G1")
wbNew.Close True 'save and close
推荐阅读
- javascript - 本机日期输入忽略 CSS
- r - 使用聚合函数后的内连接
- java - CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR,UnexpectedAlertBehaviour.IGNORE)和处理警报仍然抛出“意外警报打开”
- javascript - 如何才能在另一个函数完成后才调用另一个函数
- c - 如何在执行 memmove() 之前正确检查值?
- php - 关于 controller.service_arguments 的信息
- oracle - WSO2 微积分器无法连接到 oracle
- excel-addins - Excel 在线 Addin officeJs + createWorkbook() 不接受 .xlsb 文件格式
- apache-spark - 使用 Google Cloud Dataproc 在 YARN 上引发意外数量的执行程序
- python - 如何检查名称是否尚未由超类定义?