I am using the following macro to convert text to numbers for all the values. Since linked server is loading the xls, the format got messed up. Columns are already formatted e.g, accounting, percentage, number....etc, but even though everything are saved as text.
So I decided to run the macro before closiong开发者_如何学Go the workbook. The macros goes like this:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Cells.Select
Range("D1").Activate
Cells.SpecialCells(xlCellTypeLastCell).Offset(1, 1).Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlPasteSpecialOperationAdd
With Selection
.VerticalAlignment = xlTop
.WrapText = False
End With
ActiveWorkbook.SaveAs "test.xls"
ActiveWorkbook.Close
End Sub
But the thing is, it pops up window to ask if I wanna save the changes, How can I fix that.
Above macro takes little longer to execute!!!
I have fixed columns(till D1) but valiable rows.
Can somebody help me to figure this out.
But the thing is, it pops up window to ask if I wanna save the changes, How can I fix that.
Add in ActiveWorkbook.Saved = True
after ActiveWorkbook.SaveAs "test.xls"
. There are a few other options here(involving suppressing the alerts, but that could affect any other open workbooks, too).
Select whatever column you want:
Sub ConvertToText()
Dim xCell As Range
Range(Cells(1, 1), Cells(1, 1).End(xlDown)).Select 'does the first column
For Each xCell In Selection
xCell.Value = CDec(xCell.Value)
Next xCell
End Sub
精彩评论