Consulting

Results 1 to 5 of 5

Thread: Paste Format

  1. #1

    Paste Format

    Hi all I need some help with formating. I have a word document which I select then paste into excel. The original word doc has been justified centre. The code I have copies and pastes. But is there a way to justify it centre of sheet I still need to be able to change values so I can't copy as picture.
    [VBA]Private Sub cmdOK_Click()
    Dim fd As FileDialog
    Dim myPath As String

    Dim xlApp As Object
    Dim xlBook As Object
    Dim xlSheet As Object
    'in the background, create an instance of XL
    Set xlApp = CreateObject("Excel.Application")
    Set xlBook = xlApp.Workbooks.Add
    Set xlSheet = xlBook.Worksheets(1)

    Selection.WholeStory
    Selection.Copy
    xlSheet.Range("e1").Select
    xlSheet.Paste
    xlApp.Visible = True
    Set xlSheet = Nothing
    Set xlBook = Nothing
    Set xlApp = Nothing

    End Sub
    [/VBA]

    Any ideas would be appreciated.
    Thanks all

  2. #2
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location

    pastespecial ???

    Quote Originally Posted by peterwmartin
    Hi all I need some help with formating. I have a word document which I select then paste into excel. The original word doc has been justified centre. The code I have copies and pastes. But is there a way to justify it centre of sheet I still need to be able to change values so I can't copy as picture.
    [vba]Private Sub cmdOK_Click()
    Dim fd As FileDialog
    Dim myPath As String

    Dim xlApp As Object
    Dim xlBook As Object
    Dim xlSheet As Object
    'in the background, create an instance of XL
    Set xlApp = CreateObject("Excel.Application")
    Set xlBook = xlApp.Workbooks.Add
    Set xlSheet = xlBook.Worksheets(1)

    Selection.WholeStory
    Selection.Copy
    xlSheet.Range("e1").Select
    'xlSheet.Paste
    xlSheet.PasteSpecial format:="Microsoft Word 8.0 Document Object"
    xlApp.Visible = True
    Set xlSheet = Nothing
    Set xlBook = Nothing
    Set xlApp = Nothing

    End Sub
    [/vba]

    Any ideas would be appreciated.
    Thanks all
    Last edited by Charlize; 01-03-2007 at 06:13 AM. Reason: Just another idea ... maybe justify the contents of the cell.

  3. #3
    Thanks Charlize,
    This pastes as a picture any tables I take over I need to edit.
    The document has tables and text.

  4. #4
    MS Excel MVP VBAX Tutor
    Joined
    Mar 2005
    Posts
    246
    Location
    You're pasting the document starting at cell E1. This gives you one paragraph per cell in column E, except that tables take up as many rows and columns as they used in Word, starting with the next cell in column E. You could apply each paragraph's alignment in Word to each cell's alignment in Excel, with partial success. You will not get line wrapping and other paragraph formatting the way a word processor would provide, because Excel isn't a word processor. There's no neat way to accomplish this, although I can think of slow, messy, buggy ways that involve merging cells and stepping through the Word paragraphs one by one.
    - Jon
    -------
    Jon Peltier, Microsoft Excel MVP
    Peltier Technical Services
    Tutorials and Custom Solutions
    http://PeltierTech.com
    _______

  5. #5
    Thanks Jon.
    I will work through it . I did see some code for if text if table etc however I can't find it again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •