VBA save as Word

strangedenial

New Member
Joined
Sep 15, 2014
Messages
39
My Bad !!!!!!!!!

The code did not work because The File location is was changed !!!

I leave the code for the ones who would use it if needed!

Sorry again !


Code:
Sub NextInvoice()
    Range("F4").Value = Range("F4").Value + 1
    Range("F5").ClearContents
End Sub

Sub Excel_to_Word()
    Dim wrdApp As Object
    Dim wrdDoc As Object
    Dim i As Integer
    Dim fName As String
    Dim fLoc As String
   
    Set wrdApp = CreateObject("Word.Application")
    wrdApp.Visible = True
    Set wrdDoc = wrdApp.Documents.Add("C:\Users\ozgur\Documents\FINANS\test.docx")
        With ActiveSheet
        .Range(.Range("A1:F27"), .Cells(.Rows.Count, 1).End(xlUp)).Copy
        End With
    fName = ActiveSheet.Range("F5").Value & "." & ActiveSheet.Range("B10").Value & "." & ActiveSheet.Range("F3").Value & "." & ActiveSheet.Range("F4").Value & ".docx"
    fLoc = "C:\Users\ozgur\Documents\FINANS\Odemeler\"
    wrdApp.Documents.Add.Content.Paste
    Application.CutCopyMode = False
    wrdApp.ActiveDocument.Saveas Filename:=fLoc & fName
    wrdApp.Application.Quit
    
Dim myPath1 As String

myPath1 = "C:\Users\ozgur\Documents\FINANS\Odemeler\"

If ActiveSheet.Range("D6").Value = "" Then
ActiveSheet.Copy
With ActiveWorkbook
.Saveas myPath1 & ActiveSheet.Range("F5").Value & "." & ActiveSheet.Range("B10").Value & "." & ActiveSheet.Range("F3").Value & "." & ActiveSheet.Range("F4").Value & ".xlsx"
.Close
NextInvoice
End With
End If

End Sub
 
Last edited:

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
If you step through the code which line is causing the error?
 
Upvote 0
Norie, the code works perfectly. It was my bad. I didn`t notice that I changed the folder name. I couldnt find how to mark the thread as SOLVED. I left the code as It might be useful to others.

Thanks again for your interest
 
Upvote 0

Forum statistics

Threads
1,214,980
Messages
6,122,563
Members
449,088
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top