자동 덮어쓰기와 함께 workbook.saveas를 사용하는 방법
이 코드 섹션에서 Excel은 항상 "파일은 이미 존재합니다. 덮어쓰시겠습니까?"라는 메시지를 표시합니다.
Application.DisplayAlerts = False
Set xls = CreateObject("Excel.Application")
Set wb = xls.Workbooks.Add
fullFilePath = importFolderPath & "\" & "A.xlsx"
wb.SaveAs fullFilePath, AccessMode:=xlExclusive, ConflictResolution:=True
wb.Close(True)
왜?db.SaveAs기존 파일을 덮어쓸지 묻는 메시지가 항상 표시됩니다.DisplayAlerts = False?
프롬프트 세트를 숨기려면xls.DisplayAlerts = False
ConflictResolution이 아니다true또는false소유물, 그것은 다음과 같아야 한다.xlLocalSessionChanges
다만, 이것은 덮어쓰기 프롬프트의 표시와는 관계가 없습니다.
Set xls = CreateObject("Excel.Application")
xls.DisplayAlerts = False
Set wb = xls.Workbooks.Add
fullFilePath = importFolderPath & "\" & "A.xlsx"
wb.SaveAs fullFilePath, AccessMode:=xlExclusive,ConflictResolution:=Excel.XlSaveConflictResolution.xlLocalSessionChanges
wb.Close (True)
SaveAs를 실행하기 전에 파일이 있으면 삭제하는 것이 좋습니다.
If Dir("f:ull\path\with\filename.xls") <> "" Then
Kill "f:ull\path\with\filename.xls"
End If
디스플레이 설정보다 쉽다알림 끄기/켜기 및 디스플레이의 경우코드 크래시로 인해 경보가 꺼진 상태로 유지되므로 동일한 세션에서 Excel을 사용할 경우 문제가 발생할 수 있습니다.
의견 차이를 양분하다
저는 다음 항목을 선호합니다.
xls.DisplayAlerts = False
wb.SaveAs fullFilePath, AccessMode:=xlExclusive, ConflictResolution:=xlLocalSessionChanges
xls.DisplayAlerts = True
드디어 맞혔네, 위의 모든 게 너무 헷갈려.
Sub SaveAndClose()
Dim wb1 As String
Application.Calculation = xlCalculationAutomatic
'this only works if the following equation is in C43 in sheet "data"
'=LEFT(MID(CELL("filename",C41),SEARCH("[",CELL("filename",C41))+1, SEARCH("]",CELL("filename",C41))-SEARCH("[",CELL("filename",C41))-1),75)
'the vba equation has double quotes everywhere that is how you use a formula in vba.
'vba code recreates this incase it gets deleted by accident.
ThisWorkbook.Sheets("Data").Range("C43").ClearContents
ThisWorkbook.Sheets("Data").Range("C43").Formula2R1C1 = _
"=LEFT(MID(CELL(""filename"",R[-2]C),SEARCH(""["",CELL(""filename"",R[-2]C))+1, SEARCH(""]"",CELL(""filename"",R[-2]C))-SEARCH(""["",CELL(""filename"",R[-2]C))-1),75)"
'https://techcommunity.microsoft.com/t5/excel/cell-reference-containing-file-name-changes-when-opening-second/m-p/2417030
wb1 = ThisWorkbook.Sheets("Data").Range("C43").Text
If ThisWorkbook.Name = wb1 Then
'MsgBox (wb1)
Workbooks(wb1).Close SaveChanges:=True
End If
End Sub
이렇게 하면 스프레드시트가 자신의 이름을 결정하고 서브가 그 이름에 대해 무언가를 실행할 수 있습니다.중복되는 용지가 여러 장 있지만 이름이 다른 경우 실수로 잘못된 용지를 닫지 않습니다.내 생각에 이건 CYA의 큰 승리야
이렇게 하면 덮어쓰기 메시지도 무시되므로 다른 워크북에서 작업하는 동안 영향을 받지 않고 다른 워크북의 백그라운드에서 코드가 자동으로 실행됩니다.
언급URL : https://stackoverflow.com/questions/14634453/how-to-use-workbook-saveas-with-automatic-overwrite
'programing' 카테고리의 다른 글
| Bash에서 도트로 구분된 버전 포맷의 두 문자열을 비교하는 방법은 무엇입니까? (0) | 2023.04.12 |
|---|---|
| WPF 어플리케이션에서 콘솔로 출력되지 않았습니까? (0) | 2023.04.12 |
| init coder a Decoder란 정확히 무엇입니까? (0) | 2023.04.12 |
| 색조 UIButton 이미지 (0) | 2023.04.12 |
| 외부 DLL 파일을 저장할 위치 (0) | 2023.04.12 |