I need to make MS word visible..please help

S

Steven

I have a macro that copies the used range from sheet1, and paste into
MS word. Actually, this macro works fine for me. I get what I want but
I want MS word is active and visible after this "paste" process.
Please someone help me...
Thank you for taking your time to read this.


________________________________________________________________


Sub MyUsedRange()
Dim ar As Range, r As Double, c As Integer, tr As Double, tc As Integer
Dim ur As Range, fr As Double, fc As Integer, tfr As Double, tfc As
Integer

On Error Resume Next
fc = ActiveSheet.Columns.Count
fr = ActiveSheet.Rows.Count
Set ur =
Union(ActiveSheet.UsedRange.SpecialCells(xlCellTypeConstants), _
ActiveSheet.UsedRange.SpecialCells(xlCellTypeFormulas))
If Err.Number = 1004 Then
Err.Clear
Set ur = ActiveSheet.UsedRange.SpecialCells(xlCellTypeConstants)
End If
If Err.Number = 1004 Then
Err.Clear
Set ur = ActiveSheet.UsedRange.SpecialCells(xlCellTypeFormulas)
End If
If Err.Number = 0 Then
For Each ar In ur.Areas

'tr = ar.Range("A1").Row + ar.Rows.Count - 1
tr = (ar.Range("A1").Row + 17) + ar.Rows.Count - 1
'tc = ar.Range("A1").Column + ar.Columns.Count - 1
tc = ar.Range("A1").Column - 1 + ar.Columns.Count - 1
If tc > c Then c = tc
If tr > r Then r = tr
tfr = ar.Range("A1").Row

'tfc = ar.Range("A1").Column
tfc = ar.Range("A1").Column - 1
If tfc < fc Then fc = tfc
If tfr < fr Then fr = tfr
Next
Range(Cells(fr, fc), Cells(r, c)).Select
ElseIf Err.Number = 1004 Then
'Range("A1").Select

End If
End Sub


Sub PasteTableToWord()

Dim obj As Object
Dim temp As String

'Activate the worksheet containing the range to be copied
Worksheets("bpv").Activate

'Calling actual used range.
Call MyUsedRange


'Format the selection
Selection.ColumnWidth = 6.35

With Selection.Font
.Name = "Arial"
.Size = 9
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
End With




'Copy the cells
Selection.Copy



'Create a word object.
Set obj = CreateObject("word.basic")



'Create a new file.
obj.filenew

'Paste the Microsoft Excel Spreadsheet object into Word
obj.EditPasteSpecial Link:=1, Class:="Excel.Sheet.5", _
DataType:="object", IconFilename:="", _
Caption:="Microsoft Excel Worksheet"



'Save the file
obj.FileSaveAs Name:="RML EF Interop.doc"


'Close Word.
'Set obj = Nothing

'Return to Microsoft Excel. If this line is not used, the
focus
'may be set to another Windows Application
' AppActivate "Word.basic"

'Deselect the selected range
'Application.CutCopyMode = False


End Sub
 
D

Dr. Stephan Kassanke

In
Steven said:
I have a macro that copies the used range from sheet1, and paste into
MS word. Actually, this macro works fine for me. I get what I want but
I want MS word is active and visible after this "paste" process.
Please someone help me...
Thank you for taking your time to read this.
[lots of code snipped]

Steven,

insert obj.visible = true after the paste action. BTW, I do not quite
understand why you create a Word.Basic object (CreateObject("word.basic")).

http://support.microsoft.com/?kbid=307216 gives you a code skeleton for
automating Word.

cheers,
Stephan
 
S

Steven

Thank you for your help, Dr. Kassanke.

I inserted "obj.visible = true" after paster action, actually I tried
this before I posted up here. Anyway I tried, and it makes Run-time
error of 438. Object type doesn't support this property or method.

And What is your recommendation about "Word.Basic object
(CreateObject("word.basic")). "? Would you tell me how you would change
to make it better.?

Thank you, Sir.
 
S

Steven

By the way, I inserted "obj.visible=true" like this

______________________________________________________________________________

Sub PasteTableToWord()

Dim obj As Object
Dim temp As String

'Activate the worksheet containing the range to be copied
Worksheets("bpv").Activate

'Select the range the of cells to be copied; update to match
'your data
'Range("b2:l34").Select
'Worksheets("EFSV").UsedRange.Select


Call MyUsedRange
'Call WorksheetLoop

'Format the selection
Selection.ColumnWidth = 6.35

With Selection.Font
.Name = "Arial"
.Size = 9
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
End With




'Copy the cells
Selection.Copy



'Create a word object.
Set obj = CreateObject("word.basic")



'Create a new file.
obj.filenew

'Paste the Microsoft Excel Spreadsheet object into Word
obj.EditPasteSpecial Link:=1, Class:="Excel.Sheet.5", _
DataType:="object", IconFilename:="", _
Caption:="Microsoft Excel Worksheet"

'Make MS Word visible
obj.Visible = True



'Save the file
obj.FileSaveAs Name:="RML EF Interop.doc"


'Close Word.
'Set obj = Nothing

'Return to Microsoft Excel. If this line is not used, the
focus
'may be set to another Windows Application
' AppActivate "Word.basic"

'Deselect the selected range
'Application.CutCopyMode = False


End Sub
 
T

Tom Ogilvy

I think you want to change

Set obj = CreateObject("word.basic")

to

Set obj = CreateObject("word.application")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top