excel - SaveCopyAs Excel VBA 后不再合并合并的单元格
问题描述
我已经合并了一定范围内的单元格。合并区域的数量因工作表而异,有些有 2 个,有些有 10 个。创建并保存新文件后,所有合并区域会将文本拉回范围中的第一个单元格。我真的想用不同的文件名保存一个精确的硬编码副本。
这是用于保存值和 SaveCopyAs 的代码部分:
Sheets("Send").Visible = True
Sheets.Select
Cells.Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveSheet.Paste
Application.CutCopyMode = False
Dim thisWb As Workbook, d As Integer
Set thisWb = ActiveWorkbook
d = InStrRev(thisWb.FullName, ".")
'ActiveWorkbook.SaveAs Filename:=Left(thisWb.FullName, d - 1) & "-Prelims" & Mid(thisWb.FullName, d)
Sheets("Send").Visible = False
Dim newFileName As String
newFileName = Left(thisWb.FullName, d - 1) & "-Prelims" & Mid(thisWb.FullName, d)
thisWb.SaveCopyAs Filename:=newFileName
这似乎应该很容易,但我无法在 SO 或其他任何地方找到答案。
解决方案
这是您的代码的外观。这对你来说应该更有效率
让我知道是否有任何问题:
Sub test()
Dim thisWb As Workbook, ws As Worksheet, d As Integer, lastRow As Long
Set ws = Sheets("Send")
lastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row 'Finds the bottom populated row
With ws.Range(ws.Cells(1, 1), ws.Cells(lastRow, 1)) 'This find the bottom of column A
.Value = .Value 'Change to text rather than formula
End With
Set thisWb = ActiveWorkbook
d = InStrRev(thisWb.FullName, ".")
Sheets("Send").Visible = False
Dim newFileName As String
newFileName = Left(thisWb.FullName, d - 1) & "-Prelims" & Mid(thisWb.FullName, d)
thisWb.SaveCopyAs Filename:=newFileName
End Sub
推荐阅读
- android - 用于 android 的 Ionic 4 硬件后退按钮在导航时无法在其他页面上运行
- python - 如何同时get.dummies和count
- nativescript - (Nativescript + Google Maps SDK)折线渐变颜色
- arrays - 值错误:使用序列(数组)设置数组元素
- html - 如何为下降线的部分着色?
- pine-script - 如何将形状垂直放置在条形上方 5 次?
- python - 根据索引向量替换数组的值
- python - Python selenium 查找复选框
- r - ggplot:两组的geom_line和geom_point叠加顺序?
- c# - Unity中的环境变量在开发和生产之间有所不同