Results 1 to 3 of 3

VBA Beginner - Copying Data from word file to a new excel document

Threaded View

  1. #1
    Registered User
    Join Date
    06-20-2020
    Location
    India
    MS-Off Ver
    10.02
    Posts
    6

    VBA Beginner - Copying Data from word file to a new excel document

    #1
    Hi,

    I am an Excel VBA noob. Could you please help me correct this code? The Excel file that gets created is corrupted/blank.

    Thanks,
    GreyFox


    Sub CopyWordtoExcel()
    
    Dim FileName As String
    Dim myExcel As Object
    Dim myWb As Object
    Dim MainData As String
    
    FileName = ActiveDocument.Name
    
    ActiveDocument.Tables(1).Select
    Selection.Cut
    Selection.TypeParagraph
    Selection.InsertBreak Type:=wdPageBreak
    Selection.PasteAndFormat (wdFormatOriginalFormatting)
    Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="1"
    Selection.GoTo What:=wdGoToBookmark, Name:="\page"
    Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.GoTo What:=wdGoToBookmark, Name:="\page"
    Selection.Delete Unit:=wdCharacter, Count:=1
    
    MainData = ActiveDocument.Content
    
    Set myExcel = CreateObject("Excel.Application")
    Set myWb = myExcel.Workbooks.Add
    Range("A1").Value = MainData
    
    Application.DisplayAlerts = False
    myWb.SaveAs FileName:="XX" & "\" & FileName & ".xls"
    
    Application.DisplayAlerts = False
    
    myWb.Close False
    Set myWb = Nothing
    Set myExcel = Nothing
    
    End Sub
    Last edited by davesexcel; 07-18-2021 at 12:14 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Macro that transfers data from excel to word document and then saves document as pdf file
    By mlcfexcel in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-08-2021, 08:47 PM
  2. Copying data out of a word document issue
    By tom.mat.walker in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 06-17-2016, 06:51 AM
  3. Replies: 0
    Last Post: 06-15-2011, 02:22 PM
  4. Replies: 0
    Last Post: 12-16-2009, 07:39 PM
  5. copying from excel to word document
    By walid66 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-02-2007, 01:36 PM
  6. Copying Cell data and pasting into word document?
    By Simon Lloyd in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-07-2006, 05:41 AM
  7. [SOLVED] Copying an Excel chart into a Word document
    By Carolyn in forum Excel General
    Replies: 7
    Last Post: 07-11-2005, 03:05 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1