Save As same path

Status
Niet open voor verdere reacties.

Luccl

Gebruiker
Lid geworden
27 mei 2021
Berichten
13
Hoi

Ik wil het document opslaan als RTF format onder dezelfde naam en plaats
maar ergens zit er iets fout in het script

Bedankt voor alle reacties

Code:
Sub Markeer_opmaak()
' Macro1 Markeer_opmaak
    Call Markeer_opmaak_body
' look for footnotes
    If ActiveDocument.Footnotes.Count >= 1 Then
    Call Markeer_opmaak_voettekst
    End If
'  look for endnotes
    If ActiveDocument.Endnotes.Count >= 1 Then
    Call Markeer_opmaak_eindnoten
    End If
'save Word
    ActiveDocument.Save

 'save and close

    Dim strDocName As String
    Dim intPos As Integer
    Dim strPath As String
    strPath = Options.DefaultFilePath(wdUserTemplatesPath)
 
    ' Find position of extension in file name
    strDocName = ActiveDocument.Name
    intPos = InStrRev(strDocName, ".")
 
    If intPos = 0 Then
 
        ' If the document has not yet been saved
        ' Ask the user to provide a file name
        strDocName = InputBox("Please enter the name " & _
            "of your document.")
    Else
 
        ' Strip off extension and add ".txt" extension
        strDocName = Left(strDocName, intPos - 1)
        strDocName = strDocName & ".rtf"
    End If
 
    ' Save file with new extension
        ActiveDocument.SaveAs2 FileName:=Dir(strPath & strDocName = strDocName & ".rtf"), _
        FileFormat:=wdFormatRTF

        ActiveDocument.Close
End Sub
 
Je slaat de rtf op in de map met sjablonen. Sowieso al niet handig, maar het is dus ook een andere plek. Kijk maar eens naar de verschillende outputs als je met F8 door de code loopt.
Code:
        strPath = Options.DefaultFilePath(wdUserTemplatesPath)
        strPath = .Path & Application.PathSeparator
 
En de hele code kan dan een stuk simpeler:
Code:
Sub Markeer_opmaak()Dim strDocName As String, strPath As String
    
    Markeer_opmaak_body
    If .Footnotes.Count >= 1 Then Markeer_opmaak_voettekst
    If .Endnotes.Count >= 1 Then Markeer_opmaak_eindnoten
    With ActiveDocument
        If .Saved = False Then
            strDocName = InputBox("Please enter the name of your document.", "Documentname")
        End If
        .Save
        strPath = .Path & Application.PathSeparator
        strDocName = Split(.Name, ".")(0) & ".rtf"
        .SaveAs2 FileName:=strPath & strDocName, FileFormat:=wdFormatRTF
        .Close
    End With
End Sub
 
Bedankt AccessGuru

alles werkt perfect
code is inderdaad veel beter voor mij is dit zeer leerzaam om de opbouw te zien

nogmaals bedankt
 
Status
Niet open voor verdere reacties.
Steun Ons

Nieuwste berichten

Terug
Bovenaan Onderaan