Here is, what I want the macro to do:
Almost all works fine, but so far I can only save files into an existing folder (New customer).
Code looks like this:
Sub openWord()
Dim folderPath As String
folderPath = "C:\Users\klebg\OneDrive\Zitekick\Kunder\Byg & Brand\TEST\New customer"
'Check if the folder exists
If Dir(folderPath, vbDirectory) = "" Then
'Folder does not exist, so create it
MkDir folderPath
Else
MsgBox "Mappe med samme navn eksisterer allerede"
End If
Set wordapp = CreateObject("word.Application")
wordapp.Documents.Open "C:\Users\Path\TEST\test.docx"
wordapp.Visible = True
'Auto save
wordapp.ActiveDocument.SaveAs "C:\Users\Path\TEST\New customer\" & Sheets("Testark").Range("A8")
wordapp.Documents.Close
wordapp.Documents.Open "C:\Users\Path\TEST\test2.docx"
wordapp.Visible = True
'Auto save
wordapp.ActiveDocument.SaveAs "C:\Users\klebg\OneDrive\Zitekick\Kunder\Byg & Brand\TEST\New customer\" & Sheets("Testark").Range("B8")
wordapp.Documents.Close
End Sub
Your line:
folderPath = "C:\Users\klebg\OneDrive\Zitekick\Kunder\Byg & Brand\TEST\New customer"
Tells your code where to save it. You need to change the definition of folderpath to something other than "New customer" if you want to save elsewhere.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.