i200yrs
New Member
- Joined
- Dec 18, 2019
- Messages
- 43
- Office Version
- 2019
- 2016
- 2013
- 2011
- 2010
- Platform
- Windows
Hello All...I got successfull vba code to copy the worksheet to different workbook.
In one worksheet cell have text with color (Title is orange, Status is blue, Plan is black).
But when I check the saved copy, the Title text color change to blue...the rest of texts are correct.
The funny thing is, when i double click that cell, the Title text color change to orange (correct color).
When select other cell, the Title text color go back to blue (wrong color).
Any idea how to fix this? thanks
Bottom line: I want a code to copy sheet into a different workbook without changing any format. I want copy exact. Thanks
Here is my code:
In one worksheet cell have text with color (Title is orange, Status is blue, Plan is black).
But when I check the saved copy, the Title text color change to blue...the rest of texts are correct.
The funny thing is, when i double click that cell, the Title text color change to orange (correct color).
When select other cell, the Title text color go back to blue (wrong color).
Any idea how to fix this? thanks
Bottom line: I want a code to copy sheet into a different workbook without changing any format. I want copy exact. Thanks
Here is my code:
VBA Code:
Public Function FileInUse(sFileName) As Boolean
On Error Resume Next
Open sFileName For Binary Access Read Lock Read As #1
Close #1
FileInUse = IIf(Err.Number > 0, True, False)
On Error GoTo 0
End Function
Sub TestCopyFile()
Dim wb As Workbook
myFilePath = "\\WeeklyMeeting\Backup\Test.xlsx"
If FileInUse(myFilePath) Then
MsgBox "File is open. Cannot overwrite!"
Else
Set wb = Workbooks.Add
ThisWorkbook.Sheets("Test").Copy Before:=wb.Sheets(1)
wb.SaveAs "\\WeeklyMeeting\Backup\Test.xlsx"
wb.Close
End If
End Sub
Last edited: