Trying to save a new word document

Status
Not open for further replies.

MikeGozna

New Member
Joined
Feb 19, 2019
Messages
10
Platform
  1. Windows
Hi Al, I hope someone could help a novice with this problem. I am writing some code which deals with opening and saving quotations. What I want to do is open a new document (document1) from my quotation template. Then i drop in some book marks, (which I have done with little problem). Now when I try to save the file with a filename which is stored in Textbox18.text on the userform i am using to open this new document, i encounter all kinds of errors.
I have tried active.document, SaveAs, SaveAs2 and every other combination I can think of. Everything returns either User-defined type not defined, object required or some other error. Please can someone just help me with some code to carry out what I thought was going to be one of the easier parts of the project.
I have encluded the SaveQuotation Sub in its entirety below. The savAs part is just one combination of many I have tried. If there is a foolproof method of saving a file please let me know. Thankyou in advance for any help.



Sub SaveQuotation_Click()
'Error checks that a surname has been entered.


If Me.TextBox4.Value = "" Then
msgbox "You must enter a customer Surname to save?", vbOKCancel
If vbYes Then
Me.TextBox4.SetFocus
Exit Sub
End If
End If


'Check to see if either a DMW Quote or a GOZNA quote has been typed out


If OpenDMWQuote.Enabled = True Then
msgbox "Please produce and PRINT either a DMW or GOZNA quotation before saving to file"
Exit Sub
Else

' Transfers the details of the quote to the 'Quotation Data' sheet

Dim erow As Integer
Dim ws As Worksheet
Set ws = Worksheets("QuotationData")

With ws


erow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row


Me.TextBox1.SetFocus
ws.Cells(erow, 1).Value = Me.TextBox1.Value
ws.Cells(erow, 2).Value = Me.TextBox17.Value
ws.Cells(erow, 4).Value = Me.CboTitle.Value
ws.Cells(erow, 3).Value = Me.TextBox6.Value
ws.Cells(erow, 5).Value = Me.TextBox5.Value
ws.Cells(erow, 6).Value = Me.TextBox4.Value
ws.Cells(erow, 7).Value = Me.TextBox2.Value
ws.Cells(erow, 8).Value = Me.TextBox3.Value
ws.Cells(erow, 9).Value = Me.TextBox12.Value
ws.Cells(erow, 10).Value = Me.TextBox11.Value
ws.Cells(erow, 11).Value = Me.TextBox10.Value
ws.Cells(erow, 12).Value = Me.TextBox9.Value
ws.Cells(erow, 13).Value = Me.TextBox8.Value
ws.Cells(erow, 14).Value = Me.TextBox7.Value
ws.Cells(erow, 15).Value = Me.TextBox16.Value
ws.Cells(erow, 16).Value = Me.TextBox14.Value
ws.Cells(erow, 17).Value = Me.TextBox13.Value


Me.TextBox1.Value = ""
Me.TextBox17.Value = ""
Me.CboTitle.Value = ""
Me.TextBox6.Value = ""
Me.TextBox5.Value = ""
Me.TextBox4.Value = ""
Me.TextBox2.Value = ""
Me.TextBox3.Value = ""
Me.TextBox12.Value = ""
Me.TextBox11.Value = ""
Me.TextBox10.Value = ""
Me.TextBox9.Value = ""
Me.TextBox8.Value = ""
Me.TextBox7.Value = ""
Me.TextBox16.Value = ""
Me.TextBox14.Value = ""
Me.TextBox13.Value = ""


End With
End If

'Saves the choosen quotaion to C:\New Dashboard\Quotations\
Dim filepath As String
filepath = "C:\Dashboard\Quotations"
Dim fname As String
fname = Me.TextBox18.Value
Dim wDoc As Document
Set wDoc = Application.Documents.Add

With wDoc
wDoc.SaveAs2 filename:=filepath + fname, _
FileFormat:=wdFormatXMLDocument, AddtoRecentFiles:=False

End With







End Sub
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Status
Not open for further replies.

Forum statistics

Threads
1,215,463
Messages
6,124,962
Members
449,200
Latest member
indiansth

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