Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 05-03-2012, 06:19 AM
rmw85 rmw85 is offline Making a Command Button that Prints, Saves and Emails Windows XP Making a Command Button that Prints, Saves and Emails Office 2010 32bit
Novice
Making a Command Button that Prints, Saves and Emails
 
Join Date: Apr 2012
Posts: 10
rmw85 is on a distinguished road
Default

Thanks for the reply.


I'm pretty sure its a template that i am working on as its a .dotm extension.

The reason for the two command codes is because i tried the one it worked great but doesnt when its opened of the website as READ ONLY so i cut that code and pasted it somewhere else and used a new code to try and figure out how to get the document out of the read only but havent had much luck with the smaller second code.

Quote:
Are you sure all your code and userform are all in the file you're using as the template, and not in, say, your 'Normal' template? Does the useform and command button appear?
The userform and button do show up and i don't have them

Quote:
Unless you're emailing the temp document, this shouldn't be necessary.
Once its filled in the finished document does get emailed and and i'm trying to save it aswell under the name. The first line is the customer name and number and thats what its being saved as and the heading of the email is.

Quote:
You say "it worked perfectly on my machine aslong as you didnt click No in any of the message boxes". Obviously, you'll need to fix that. I note, for example, that you have code that asks the user whether a certain folder exists. Even if the user answers no to that prompt, your code then tries to save the file there. It's bound to fall over in that case. You either need to create the folder without asking the user or, if they choose 'no', asking them where to save the filke to and not proceeding until they've nominated a valid destination, to which the file is then saved.
At this point the not exiting the code properly when clicking as of now might just be the way it is. They are going to have to copy to that location anyway and most of the code is copied and pasted from code i found online and then tweaked to work properly when clicked yes. I tried having the code just run anyway but was getting errors so as of now it is what it is and the users will have to click ok anyway. More of a workaround then a fix for now.

I know the basics of word but once i get further into detail with macro's and Visual Basic i'm basically teaching myself as i'm building this document.

Thanks,
Randy


Here is some code i got to come close to what i'm attempting. The formatting is still alittle messed up as in the margins and spacing but it shows the tables in there. I put a note in there which is just a place holder to when i figured out how to acheived what i'm looking for then i was going to add the first code (the longer one) and piece that into there and it should in theory work the way i'd like it to.
Code:
Private Sub CommandButton1_Click()
    Dim oSection As Section
    Dim r As Range
    Dim TempDoc As Document
    Dim FirstPara As String
 
    For Each oSection In ActiveDocument.Sections
        Set r = oSection.Range
        r.End = r.End - 1
        Set TempDoc = Documents.Add
        With TempDoc
            ActiveDocument.Paragraphs(1).Range.FormattedText = r
            FirstPara = r.Paragraphs(1).Range.FormattedText
            FirstPara = Left(FirstPara, Len(FirstPara) - 1)
            ChangeFileOpenDirectory "E:\Documents and Settings\" & Environ("username") & "\Desktop\EMS\"
            .SaveAs FileName:=FirstPara & ".docx"
    'Dont have this close yet make it print then email and close
            .Close
        End With
        Set r = Nothing
        Set TempDoc = Nothing
    Next
End Sub

Last edited by rmw85; 05-03-2012 at 06:54 AM. Reason: Added code
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Making a Command Button that Prints, Saves and Emails Command Button doesnt work on network rmw85 Word VBA 1 04-25-2012 01:02 PM
Making a Command Button that Prints, Saves and Emails VBA Print Command Prints Document Twice HorizonSC Word 2 11-15-2011 03:26 AM
Check Boxes and Command Buttons Micky P Word VBA 0 10-27-2011 01:06 AM
Making a Command Button that Prints, Saves and Emails Command Button cksm4 Word VBA 7 02-27-2011 08:47 PM
Making a Command Button that Prints, Saves and Emails Making a button to open an Access Dbase aubreylc Outlook 2 04-07-2010 12:53 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:05 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft