Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How do I make one column or row always visible? | Excel Discussion (Misc queries) | |||
Make Object(s) Visible | Excel Discussion (Misc queries) | |||
How to make visible all text in cell with word wrap on | Excel Discussion (Misc queries) | |||
Word art and drawings are not visible | Excel Discussion (Misc queries) | |||
make outlook visible | Excel Programming |