[英]Convert VBA unmerge and fil to VBscript unmerge and fill
Hello I am trying to convert VBA to VBscript but having trouble as I do not know where to start. 您好,我正在尝试将VBA转换为VBscript,但是由于不知道从哪里开始而遇到了麻烦。 Any help is appreciated.
任何帮助表示赞赏。
VBA: Un-merging cells and then filling data to those cells from original merged data cell. VBA:取消合并单元格,然后从原始合并的数据单元格向这些单元格填充数据。
Sub UnMergeFill()
Dim cell As Range, joinedCells As Range
For Each cell In ThisWorkbook.ActiveSheet.UsedRange
If cell.MergeCells Then
Set joinedCells = cell.MergeArea
cell.MergeCells = False
joinedCells.Value = cell.Value
End If
Next
End Sub
VBScript: I have the start of the code to open the correct excel file and save and close but not the modification the VBA script is doing. VBScript:我从代码的开头开始打开正确的excel文件并保存并关闭,但没有VBA脚本所做的修改。
'create the excel object
Set objExcel = CreateObject("Excel.Application")
'view the excel program and file, set to false to hide the whole process
objExcel.Visible = True
'open an excel file (make sure to change the location) .xls for 2003 or earlier
Set objWorkbook = objExcel.Workbooks.Open("C:\Users\Desktop\vbsTest.xlsx")
'save the existing excel file
objWorkbook.Save
'close the workbook
objWorkbook.Close
'exit the excel program
objExcel.Quit
'release objects
Set objExcel = Nothing
Set objWorkbook = Nothing
VBscript Code: VBscript代码:
'Microsoft Excel Automation
':: Open, unmerge cells and fill then save
'---------------------------------
'create the excel object
Set objExcel = CreateObject("Excel.Application")
'view the excel program and file, set to false to hide the whole process
objExcel.Visible = True
'open an excel file (make sure to change the location) .xls for 2003 or earlier
Set objWorkbook = objExcel.Workbooks.Open("C:\Users\Desktop\Book3.xlsx")
Dim cell
Dim joinedCells
For Each cell In objWorkbook.ActiveSheet.UsedRange
If cell.MergeCells Then
Set joinedCells = cell.MergeArea
cell.MergeCells = False
joinedCells.Value = cell.Value
End If
Next
'save the existing excel file
objWorkbook.Save
'close the workbook
objWorkbook.Close
'exit the excel program
objExcel.Quit
'release objects
Set objExcel = Nothing
Set objWorkbook = Nothing
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.