Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default I need to make MS word visible..please help

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(xlCellTyp eConstants), _
ActiveSheet.UsedRange.SpecialCells(xlCellTypeFormu las))
If Err.Number = 1004 Then
Err.Clear
Set ur = ActiveSheet.UsedRange.SpecialCells(xlCellTypeConst ants)
End If
If Err.Number = 1004 Then
Err.Clear
Set ur = ActiveSheet.UsedRange.SpecialCells(xlCellTypeFormu las)
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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default I need to make MS word visible..please help

In ups.com,
Steven wrote:
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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default I need to make MS word visible..please help

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.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default I need to make MS word visible..please help

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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default I need to make MS word visible..please help

I think you want to change

Set obj = CreateObject("word.basic")

to

Set obj = CreateObject("word.application")

--
Regards,
Tom Ogilvy


"Steven" wrote in message
oups.com...
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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I make one column or row always visible? Ao Excel Discussion (Misc queries) 8 April 23rd 23 09:01 PM
Make Object(s) Visible Dennis Excel Discussion (Misc queries) 2 May 19th 09 06:24 PM
How to make visible all text in cell with word wrap on Al Excel Discussion (Misc queries) 0 September 18th 07 05:20 PM
Word art and drawings are not visible synlupri Excel Discussion (Misc queries) 0 October 10th 06 09:11 PM
make outlook visible gopher Excel Programming 5 January 5th 05 06:15 PM


All times are GMT +1. The time now is 07:42 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"