Word document?

Daniellawson

Board Regular
Joined
Oct 9, 2002
Messages
61
Is it possible to get a word Document to open on the click of a button with certain values from my database?

e.g...

Name
Number

GRADE


(And then maybe it auto prints of this information?) - not essential..


thanks
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Juan Pablo González

MrExcel MVP
Joined
Feb 8, 2002
Messages
11,959
You can control Word from Excel (Or Access, since you didn't mention where's your database) with VBA, but, it's not clear what you want (You say that you want to open a document, but then you also say that you want certain values in it, so, is it a new document ?)
 

Jack in the UK

Well-known Member
Joined
Feb 16, 2002
Messages
3,215
Hi

I have made this script so range A1 to A20 is paste over to word does this help, i suggest edit teh range to your requirements

Jack

Place this code in normal standard module and link to command button

Sub Excel_to_Word_JackintheUK()

Range("A1:A20").Select
Selection.Copy

Set Word6 = CreateObject("Word.Basic")
With Word6
If UCase(Left(Application.OperatingSystem, 3)) <> "MAC" Then
.AppRestore
.AppMaximize 1
Else
AppActivate "Microsoft Word"
End If
.FileNewDefault
'.InsertPara
.Insert "JACK - Test from Excel"
.startofline 15
' .Bold
' .CenterPara
'.startofline 15
Selection.PasteSpecial Paste:=xlValues, operation:=xlNone, _
skipblanks:=False, Transpose:=False
Application.CutCopyMode = False

End With


' MARKER Excel to WORD
End Sub
 

Daniellawson

Board Regular
Joined
Oct 9, 2002
Messages
61
I typed that in my button code.. (For a test)

Private Sub SendLetter_Click()
Sub Excel_to_Word_JackintheUK()

Range("A1:A20").Select
Selection.Copy

Set Word6 = CreateObject("Word.Basic")
With Word6
If UCase(Left(Application.OperatingSystem, 3)) <> "MAC" Then
.AppRestore
.AppMaximize 1
Else
AppActivate "Microsoft Word"
End If
.FileNewDefault
'.InsertPara
.Insert "JACK - Test from Excel"
.startofline 15
' .Bold
' .CenterPara
'.startofline 15
Selection.PasteSpecial Paste:=xlValues, operation:=xlNone, _
skipblanks:=False, Transpose:=False
Application.CutCopyMode = False

End With


' MARKER Excel to WORD
End Sub

End Sub


But i get the error :

COMPILE ERROR - EXPECTED END SUB

then a yellow arroe pointing to Private Sub SendLetter_Click()..

Probably something simple but im a newbie :)

thnx
 

Jack in the UK

Well-known Member
Joined
Feb 16, 2002
Messages
3,215
OK you have not done as i have instructed the private sub DELETE it

put this in and link command button - perfect for me..

Sub Excel_to_Word_JackintheUK()

Range("A1:A20").Select
Selection.Copy
Sub Word()
Set Word6 = CreateObject("Word.Basic")
With Word6
If UCase(Left(Application.OperatingSystem, 3)) <> "MAC" Then
.AppRestore
.AppMaximize 1
Else
AppActivate "Microsoft Word"
End If
.FileNewDefault
'.InsertPara
.Insert "JACK - Test from Excel"
.startofline 15
' .Bold
' .CenterPara
'.startofline 15
'Selection.PasteSpecial Paste:=xlValues, operation:=xlNone,
'skipblanks:=False, Transpose:=False
Application.CutCopyMode = False

End With
 

Forum statistics

Threads
1,144,329
Messages
5,723,732
Members
422,512
Latest member
MHau5

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
Top