【发布时间】:2019-06-20 03:59:12
【问题描述】:
我正在尝试取消合并和复制 xlsx 文件文件夹的数据。
另外,两个宏都按预期工作。当我组合宏(通过“调用”)时,它会执行但随后将我带回宏屏幕。它没有给我任何错误,但我需要关闭 excel 重新开始。
我猜“UnMergeFill”宏不适合自动打开?
我尝试过使用“呼叫”以及仅使用子名称。我也尝试将潜艇分成不同的模块。
Sub AllWorkbooks()
Dim MyFolder As String
Dim MyFile As String
Dim wbk As Workbook
On Error Resume Next
Application.ScreenUpdating = False
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Please select a folder"
.Show
.AllowMultiSelect = False
If .SelectedItems.Count = 0 Then
MsgBox "You did not select a folder"
Exit Sub
End If
MyFolder = .SelectedItems(1) & "\"
End With
MyFile = Dir(MyFolder)
Do While MyFile <> “”
Set wbk = Workbooks.Open(Filename:=MyFolder & MyFile)
UnMergeFill
wbk.Close savechanges:=True
MyFile = Dir
Loop
Application.ScreenUpdating = True
End Sub
Call 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
'''
【问题讨论】:
-
首先,注释掉或者去掉
On Error Resume Next。代码会抛出任何错误吗?其次,您不能在一行中有Call Sub UnMergeFill()。Call似乎是一个错字。第三,您打算让UnMergeFill处理ThisWorkbook还是您正在打开的工作簿? -
感谢您的反馈。我希望它可以在打开的工作簿上工作。 Mikku 的解决方案奏效了。