Need macro to transfer Word data into Excel The 2019 Stack Overflow Developer Survey Results...

Can we generate random numbers using irrational numbers like π and e?

Deal with toxic manager when you can't quit

Variable with quotation marks "$()"

1960s short story making fun of James Bond-style spy fiction

Working through the single responsibility principle (SRP) in Python when calls are expensive

Did the UK government pay "millions and millions of dollars" to try to snag Julian Assange?

How do you keep chess fun when your opponent constantly beats you?

One-dimensional Japanese puzzle

What information about me do stores get via my credit card?

Does Parliament hold absolute power in the UK?

First use of “packing” as in carrying a gun

Didn't get enough time to take a Coding Test - what to do now?

How do spell lists change if the party levels up without taking a long rest?

Why can't devices on different VLANs, but on the same subnet, communicate?

How to type a long/em dash `—`

Drawing arrows from one table cell reference to another

Loose spokes after only a few rides

Match Roman Numerals

Huge performance difference of the command find with and without using %M option to show permissions

How did the audience guess the pentatonic scale in Bobby McFerrin's presentation?

Mortgage adviser recommends a longer term than necessary combined with overpayments

how can a perfect fourth interval be considered either consonant or dissonant?

Is every episode of "Where are my Pants?" identical?

How do I design a circuit to convert a 100 mV and 50 Hz sine wave to a square wave?



Need macro to transfer Word data into Excel



The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)Excel 2010 macro to separate a large data file into workbooksMS Excel data validator does not accept call to the custom macroCTRL+D in Excel 2010 fills values and formatting, but I want it to only fill values/formulasMove rows to new sheets in excelHow can I edit this macro to loop through the results?Reformat data through macro excel 2010?Need an Excel Macro to sum a variable length rangeSheet name dynamically assigned from a cell valueExcel VBA: Creating Hyperlinks Type MismatchExcel macro stopped working after Windows update kb4103729





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I am very new to VBA and need help ! I have VB macro in Excel that grabs the data from a Word document and imports it into Excel worksheet. Currently, the code in macro has expression that clears the active worksheet and places the new records. However, I need only to update active sheet with new records, or add new records. So, trying to figure out how to accomplish it within the existing code.



Here is the macro:



Sub getWordFormData()
Dim wdApp As New Word.Application
Dim myDoc As Word.Document
Dim CCtl As Word.ContentControl
Dim myFolder As String, strFile As String
Dim myWkSht As Worksheet, i As Long, j As Long

myFolder = "C:UserszsirotiloDocumentsRetention DBInterviews"
Application.ScreenUpdating = False

If myFolder = "" Then Exit Sub
Set myWkSht = ActiveSheet
ActiveSheet.Cells.Clear

Range("A1") = "Company Name"
Range("A1").Font.Bold = True
Range("C1") = "Date of Interview"
Range("C1").Font.Bold = True
Range("D1") = "Type of Company by Number(see Case Notes)"
Range("D1").Font.Bold = True

i = myWkSht.Cells(myWkSht.Rows.Count, 1).End(xlUp).Row
strFile = Dir(myFolder & "*.docx", vbNormal)

While strFile <> ""
i = i + 1

Set myDoc = wdApp.Documents.Open(Filename:=myFolder & "" & strFile,
AddToRecentFiles:=False, Visible:=False)

With myDoc
j = 0
For Each CCtl In .ContentControls
j = j + 1
myWkSht.Cells(i, j) = CCtl.Range.Text
Next
myWkSht.Columns.ColumnWidth = 25
End With
myDoc.Close SaveChanges:=False
strFile = Dir()
Wend
wdApp.Quit
Set myDoc = Nothing: Set wdApp = Nothing: Set myWkSht = Nothing
Application.ScreenUpdating = True

End Sub









share|improve this question























  • Does the Word document store all of these records or do you recieve a Word document that only has new records?

    – Ben Sampica
    Aug 20 '15 at 13:29











  • I receive Word docs with only new records ans save into specific folder. So there will be new docs coming all the time that need to be transfered into one master excel worksheet.

    – YoniH
    Aug 20 '15 at 13:30













  • I think just by removing Activesheet.Cells.Clear you should be able to achieve what you're looking for. I'm on mobile so cannot provide a entire answer at the moment.

    – Ben Sampica
    Aug 20 '15 at 13:41











  • Thank you. I tried that and it works. However, the issue is that I inhereted master excel sheet with data and 1) with ActiveSheet.Clear in macro it overrides all previous records with new ones AND 2) without ActiveSheet.Clear - it creates duplicates of previous records everytime the macro is ran, since it looks for Word docs in the specified folder.

    – YoniH
    Aug 20 '15 at 13:46











  • So move 'processed' word documents to another folder, unless you want to store the files processed in a worksheet and have it run through each one and check document names. That seems like a crazy amount of work for a simple folder switching solution.

    – Ben Sampica
    Aug 20 '15 at 13:56


















0















I am very new to VBA and need help ! I have VB macro in Excel that grabs the data from a Word document and imports it into Excel worksheet. Currently, the code in macro has expression that clears the active worksheet and places the new records. However, I need only to update active sheet with new records, or add new records. So, trying to figure out how to accomplish it within the existing code.



Here is the macro:



Sub getWordFormData()
Dim wdApp As New Word.Application
Dim myDoc As Word.Document
Dim CCtl As Word.ContentControl
Dim myFolder As String, strFile As String
Dim myWkSht As Worksheet, i As Long, j As Long

myFolder = "C:UserszsirotiloDocumentsRetention DBInterviews"
Application.ScreenUpdating = False

If myFolder = "" Then Exit Sub
Set myWkSht = ActiveSheet
ActiveSheet.Cells.Clear

Range("A1") = "Company Name"
Range("A1").Font.Bold = True
Range("C1") = "Date of Interview"
Range("C1").Font.Bold = True
Range("D1") = "Type of Company by Number(see Case Notes)"
Range("D1").Font.Bold = True

i = myWkSht.Cells(myWkSht.Rows.Count, 1).End(xlUp).Row
strFile = Dir(myFolder & "*.docx", vbNormal)

While strFile <> ""
i = i + 1

Set myDoc = wdApp.Documents.Open(Filename:=myFolder & "" & strFile,
AddToRecentFiles:=False, Visible:=False)

With myDoc
j = 0
For Each CCtl In .ContentControls
j = j + 1
myWkSht.Cells(i, j) = CCtl.Range.Text
Next
myWkSht.Columns.ColumnWidth = 25
End With
myDoc.Close SaveChanges:=False
strFile = Dir()
Wend
wdApp.Quit
Set myDoc = Nothing: Set wdApp = Nothing: Set myWkSht = Nothing
Application.ScreenUpdating = True

End Sub









share|improve this question























  • Does the Word document store all of these records or do you recieve a Word document that only has new records?

    – Ben Sampica
    Aug 20 '15 at 13:29











  • I receive Word docs with only new records ans save into specific folder. So there will be new docs coming all the time that need to be transfered into one master excel worksheet.

    – YoniH
    Aug 20 '15 at 13:30













  • I think just by removing Activesheet.Cells.Clear you should be able to achieve what you're looking for. I'm on mobile so cannot provide a entire answer at the moment.

    – Ben Sampica
    Aug 20 '15 at 13:41











  • Thank you. I tried that and it works. However, the issue is that I inhereted master excel sheet with data and 1) with ActiveSheet.Clear in macro it overrides all previous records with new ones AND 2) without ActiveSheet.Clear - it creates duplicates of previous records everytime the macro is ran, since it looks for Word docs in the specified folder.

    – YoniH
    Aug 20 '15 at 13:46











  • So move 'processed' word documents to another folder, unless you want to store the files processed in a worksheet and have it run through each one and check document names. That seems like a crazy amount of work for a simple folder switching solution.

    – Ben Sampica
    Aug 20 '15 at 13:56














0












0








0








I am very new to VBA and need help ! I have VB macro in Excel that grabs the data from a Word document and imports it into Excel worksheet. Currently, the code in macro has expression that clears the active worksheet and places the new records. However, I need only to update active sheet with new records, or add new records. So, trying to figure out how to accomplish it within the existing code.



Here is the macro:



Sub getWordFormData()
Dim wdApp As New Word.Application
Dim myDoc As Word.Document
Dim CCtl As Word.ContentControl
Dim myFolder As String, strFile As String
Dim myWkSht As Worksheet, i As Long, j As Long

myFolder = "C:UserszsirotiloDocumentsRetention DBInterviews"
Application.ScreenUpdating = False

If myFolder = "" Then Exit Sub
Set myWkSht = ActiveSheet
ActiveSheet.Cells.Clear

Range("A1") = "Company Name"
Range("A1").Font.Bold = True
Range("C1") = "Date of Interview"
Range("C1").Font.Bold = True
Range("D1") = "Type of Company by Number(see Case Notes)"
Range("D1").Font.Bold = True

i = myWkSht.Cells(myWkSht.Rows.Count, 1).End(xlUp).Row
strFile = Dir(myFolder & "*.docx", vbNormal)

While strFile <> ""
i = i + 1

Set myDoc = wdApp.Documents.Open(Filename:=myFolder & "" & strFile,
AddToRecentFiles:=False, Visible:=False)

With myDoc
j = 0
For Each CCtl In .ContentControls
j = j + 1
myWkSht.Cells(i, j) = CCtl.Range.Text
Next
myWkSht.Columns.ColumnWidth = 25
End With
myDoc.Close SaveChanges:=False
strFile = Dir()
Wend
wdApp.Quit
Set myDoc = Nothing: Set wdApp = Nothing: Set myWkSht = Nothing
Application.ScreenUpdating = True

End Sub









share|improve this question














I am very new to VBA and need help ! I have VB macro in Excel that grabs the data from a Word document and imports it into Excel worksheet. Currently, the code in macro has expression that clears the active worksheet and places the new records. However, I need only to update active sheet with new records, or add new records. So, trying to figure out how to accomplish it within the existing code.



Here is the macro:



Sub getWordFormData()
Dim wdApp As New Word.Application
Dim myDoc As Word.Document
Dim CCtl As Word.ContentControl
Dim myFolder As String, strFile As String
Dim myWkSht As Worksheet, i As Long, j As Long

myFolder = "C:UserszsirotiloDocumentsRetention DBInterviews"
Application.ScreenUpdating = False

If myFolder = "" Then Exit Sub
Set myWkSht = ActiveSheet
ActiveSheet.Cells.Clear

Range("A1") = "Company Name"
Range("A1").Font.Bold = True
Range("C1") = "Date of Interview"
Range("C1").Font.Bold = True
Range("D1") = "Type of Company by Number(see Case Notes)"
Range("D1").Font.Bold = True

i = myWkSht.Cells(myWkSht.Rows.Count, 1).End(xlUp).Row
strFile = Dir(myFolder & "*.docx", vbNormal)

While strFile <> ""
i = i + 1

Set myDoc = wdApp.Documents.Open(Filename:=myFolder & "" & strFile,
AddToRecentFiles:=False, Visible:=False)

With myDoc
j = 0
For Each CCtl In .ContentControls
j = j + 1
myWkSht.Cells(i, j) = CCtl.Range.Text
Next
myWkSht.Columns.ColumnWidth = 25
End With
myDoc.Close SaveChanges:=False
strFile = Dir()
Wend
wdApp.Quit
Set myDoc = Nothing: Set wdApp = Nothing: Set myWkSht = Nothing
Application.ScreenUpdating = True

End Sub






microsoft-excel microsoft-excel-2010 macros






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Aug 20 '15 at 13:18









YoniHYoniH

12




12













  • Does the Word document store all of these records or do you recieve a Word document that only has new records?

    – Ben Sampica
    Aug 20 '15 at 13:29











  • I receive Word docs with only new records ans save into specific folder. So there will be new docs coming all the time that need to be transfered into one master excel worksheet.

    – YoniH
    Aug 20 '15 at 13:30













  • I think just by removing Activesheet.Cells.Clear you should be able to achieve what you're looking for. I'm on mobile so cannot provide a entire answer at the moment.

    – Ben Sampica
    Aug 20 '15 at 13:41











  • Thank you. I tried that and it works. However, the issue is that I inhereted master excel sheet with data and 1) with ActiveSheet.Clear in macro it overrides all previous records with new ones AND 2) without ActiveSheet.Clear - it creates duplicates of previous records everytime the macro is ran, since it looks for Word docs in the specified folder.

    – YoniH
    Aug 20 '15 at 13:46











  • So move 'processed' word documents to another folder, unless you want to store the files processed in a worksheet and have it run through each one and check document names. That seems like a crazy amount of work for a simple folder switching solution.

    – Ben Sampica
    Aug 20 '15 at 13:56



















  • Does the Word document store all of these records or do you recieve a Word document that only has new records?

    – Ben Sampica
    Aug 20 '15 at 13:29











  • I receive Word docs with only new records ans save into specific folder. So there will be new docs coming all the time that need to be transfered into one master excel worksheet.

    – YoniH
    Aug 20 '15 at 13:30













  • I think just by removing Activesheet.Cells.Clear you should be able to achieve what you're looking for. I'm on mobile so cannot provide a entire answer at the moment.

    – Ben Sampica
    Aug 20 '15 at 13:41











  • Thank you. I tried that and it works. However, the issue is that I inhereted master excel sheet with data and 1) with ActiveSheet.Clear in macro it overrides all previous records with new ones AND 2) without ActiveSheet.Clear - it creates duplicates of previous records everytime the macro is ran, since it looks for Word docs in the specified folder.

    – YoniH
    Aug 20 '15 at 13:46











  • So move 'processed' word documents to another folder, unless you want to store the files processed in a worksheet and have it run through each one and check document names. That seems like a crazy amount of work for a simple folder switching solution.

    – Ben Sampica
    Aug 20 '15 at 13:56

















Does the Word document store all of these records or do you recieve a Word document that only has new records?

– Ben Sampica
Aug 20 '15 at 13:29





Does the Word document store all of these records or do you recieve a Word document that only has new records?

– Ben Sampica
Aug 20 '15 at 13:29













I receive Word docs with only new records ans save into specific folder. So there will be new docs coming all the time that need to be transfered into one master excel worksheet.

– YoniH
Aug 20 '15 at 13:30







I receive Word docs with only new records ans save into specific folder. So there will be new docs coming all the time that need to be transfered into one master excel worksheet.

– YoniH
Aug 20 '15 at 13:30















I think just by removing Activesheet.Cells.Clear you should be able to achieve what you're looking for. I'm on mobile so cannot provide a entire answer at the moment.

– Ben Sampica
Aug 20 '15 at 13:41





I think just by removing Activesheet.Cells.Clear you should be able to achieve what you're looking for. I'm on mobile so cannot provide a entire answer at the moment.

– Ben Sampica
Aug 20 '15 at 13:41













Thank you. I tried that and it works. However, the issue is that I inhereted master excel sheet with data and 1) with ActiveSheet.Clear in macro it overrides all previous records with new ones AND 2) without ActiveSheet.Clear - it creates duplicates of previous records everytime the macro is ran, since it looks for Word docs in the specified folder.

– YoniH
Aug 20 '15 at 13:46





Thank you. I tried that and it works. However, the issue is that I inhereted master excel sheet with data and 1) with ActiveSheet.Clear in macro it overrides all previous records with new ones AND 2) without ActiveSheet.Clear - it creates duplicates of previous records everytime the macro is ran, since it looks for Word docs in the specified folder.

– YoniH
Aug 20 '15 at 13:46













So move 'processed' word documents to another folder, unless you want to store the files processed in a worksheet and have it run through each one and check document names. That seems like a crazy amount of work for a simple folder switching solution.

– Ben Sampica
Aug 20 '15 at 13:56





So move 'processed' word documents to another folder, unless you want to store the files processed in a worksheet and have it run through each one and check document names. That seems like a crazy amount of work for a simple folder switching solution.

– Ben Sampica
Aug 20 '15 at 13:56










1 Answer
1






active

oldest

votes


















0














It should work by removing the line ActiveSheet.Cells.Clear, because this is the line that removes the content of the cells.



The line i = myWkSht.Cells(myWkSht.Rows.Count, 1).End(xlUp).Row is used to know the last row with content to write the new content from then. So it will work as long as the last row has content on the first column.



To avoid to read the same files over and over, it's needed to move the already exported files to another folder. My idea is this:




  1. Create a folder, for example:C:UserszsirotiloDocumentsRetention DBExported.


  2. Add the line exportedFolder = "C:UserszsirotiloDocumentsRetention DBExported" after the line that defines the variable myFolder.



  3. After the line myDoc.Close SaveChanges:=False add the following lines:



        FileCopy myDoc, exportedFolder & "" & strFile 'copy word file to Exported folder
    Kill myDoc 'deletes the word file



Make a backup of the Word files on C:UserszsirotiloDocumentsRetention DBInterviews before testing because it will delete the files.






share|improve this answer


























  • The issue is that I inhereted master excel sheet with data and 1) with ActiveSheet.Clear in macro it overrides all previous records with new ones AND 2) without ActiveSheet.Clear - it creates duplicates of previous records everytime the macro is ran, since it looks for Word docs in the specified folder.

    – YoniH
    Aug 20 '15 at 13:48











  • @YoniH I modified my answer to avoid the duplicates.

    – jcbermu
    Aug 20 '15 at 14:08











  • Thanks, I get debugger when I add as follows: myFolder = "C:UserszsirotiloDocumentsRetention DBInterviews" ExportedFolder = "C:UserszsirotiloDocumentsRetention DBInterviews - Exported" and then myDoc.Close SaveChanges:=False FileCopy myDoc, ExportedFolder & "" & strFile Kill myDoc

    – YoniH
    Aug 20 '15 at 14:28













  • @YoniH Do you mean an error? If the Word files are read only killwill fail

    – jcbermu
    Aug 20 '15 at 14:39











  • Sorry, I meant debugger error. The word docs are protected (they are generated from the restricted word form template). Debugger error picks up this expression FileCopy myDoc, ExportedFolder & "" & strFile

    – YoniH
    Aug 20 '15 at 14:43














Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f960170%2fneed-macro-to-transfer-word-data-into-excel%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














It should work by removing the line ActiveSheet.Cells.Clear, because this is the line that removes the content of the cells.



The line i = myWkSht.Cells(myWkSht.Rows.Count, 1).End(xlUp).Row is used to know the last row with content to write the new content from then. So it will work as long as the last row has content on the first column.



To avoid to read the same files over and over, it's needed to move the already exported files to another folder. My idea is this:




  1. Create a folder, for example:C:UserszsirotiloDocumentsRetention DBExported.


  2. Add the line exportedFolder = "C:UserszsirotiloDocumentsRetention DBExported" after the line that defines the variable myFolder.



  3. After the line myDoc.Close SaveChanges:=False add the following lines:



        FileCopy myDoc, exportedFolder & "" & strFile 'copy word file to Exported folder
    Kill myDoc 'deletes the word file



Make a backup of the Word files on C:UserszsirotiloDocumentsRetention DBInterviews before testing because it will delete the files.






share|improve this answer


























  • The issue is that I inhereted master excel sheet with data and 1) with ActiveSheet.Clear in macro it overrides all previous records with new ones AND 2) without ActiveSheet.Clear - it creates duplicates of previous records everytime the macro is ran, since it looks for Word docs in the specified folder.

    – YoniH
    Aug 20 '15 at 13:48











  • @YoniH I modified my answer to avoid the duplicates.

    – jcbermu
    Aug 20 '15 at 14:08











  • Thanks, I get debugger when I add as follows: myFolder = "C:UserszsirotiloDocumentsRetention DBInterviews" ExportedFolder = "C:UserszsirotiloDocumentsRetention DBInterviews - Exported" and then myDoc.Close SaveChanges:=False FileCopy myDoc, ExportedFolder & "" & strFile Kill myDoc

    – YoniH
    Aug 20 '15 at 14:28













  • @YoniH Do you mean an error? If the Word files are read only killwill fail

    – jcbermu
    Aug 20 '15 at 14:39











  • Sorry, I meant debugger error. The word docs are protected (they are generated from the restricted word form template). Debugger error picks up this expression FileCopy myDoc, ExportedFolder & "" & strFile

    – YoniH
    Aug 20 '15 at 14:43


















0














It should work by removing the line ActiveSheet.Cells.Clear, because this is the line that removes the content of the cells.



The line i = myWkSht.Cells(myWkSht.Rows.Count, 1).End(xlUp).Row is used to know the last row with content to write the new content from then. So it will work as long as the last row has content on the first column.



To avoid to read the same files over and over, it's needed to move the already exported files to another folder. My idea is this:




  1. Create a folder, for example:C:UserszsirotiloDocumentsRetention DBExported.


  2. Add the line exportedFolder = "C:UserszsirotiloDocumentsRetention DBExported" after the line that defines the variable myFolder.



  3. After the line myDoc.Close SaveChanges:=False add the following lines:



        FileCopy myDoc, exportedFolder & "" & strFile 'copy word file to Exported folder
    Kill myDoc 'deletes the word file



Make a backup of the Word files on C:UserszsirotiloDocumentsRetention DBInterviews before testing because it will delete the files.






share|improve this answer


























  • The issue is that I inhereted master excel sheet with data and 1) with ActiveSheet.Clear in macro it overrides all previous records with new ones AND 2) without ActiveSheet.Clear - it creates duplicates of previous records everytime the macro is ran, since it looks for Word docs in the specified folder.

    – YoniH
    Aug 20 '15 at 13:48











  • @YoniH I modified my answer to avoid the duplicates.

    – jcbermu
    Aug 20 '15 at 14:08











  • Thanks, I get debugger when I add as follows: myFolder = "C:UserszsirotiloDocumentsRetention DBInterviews" ExportedFolder = "C:UserszsirotiloDocumentsRetention DBInterviews - Exported" and then myDoc.Close SaveChanges:=False FileCopy myDoc, ExportedFolder & "" & strFile Kill myDoc

    – YoniH
    Aug 20 '15 at 14:28













  • @YoniH Do you mean an error? If the Word files are read only killwill fail

    – jcbermu
    Aug 20 '15 at 14:39











  • Sorry, I meant debugger error. The word docs are protected (they are generated from the restricted word form template). Debugger error picks up this expression FileCopy myDoc, ExportedFolder & "" & strFile

    – YoniH
    Aug 20 '15 at 14:43
















0












0








0







It should work by removing the line ActiveSheet.Cells.Clear, because this is the line that removes the content of the cells.



The line i = myWkSht.Cells(myWkSht.Rows.Count, 1).End(xlUp).Row is used to know the last row with content to write the new content from then. So it will work as long as the last row has content on the first column.



To avoid to read the same files over and over, it's needed to move the already exported files to another folder. My idea is this:




  1. Create a folder, for example:C:UserszsirotiloDocumentsRetention DBExported.


  2. Add the line exportedFolder = "C:UserszsirotiloDocumentsRetention DBExported" after the line that defines the variable myFolder.



  3. After the line myDoc.Close SaveChanges:=False add the following lines:



        FileCopy myDoc, exportedFolder & "" & strFile 'copy word file to Exported folder
    Kill myDoc 'deletes the word file



Make a backup of the Word files on C:UserszsirotiloDocumentsRetention DBInterviews before testing because it will delete the files.






share|improve this answer















It should work by removing the line ActiveSheet.Cells.Clear, because this is the line that removes the content of the cells.



The line i = myWkSht.Cells(myWkSht.Rows.Count, 1).End(xlUp).Row is used to know the last row with content to write the new content from then. So it will work as long as the last row has content on the first column.



To avoid to read the same files over and over, it's needed to move the already exported files to another folder. My idea is this:




  1. Create a folder, for example:C:UserszsirotiloDocumentsRetention DBExported.


  2. Add the line exportedFolder = "C:UserszsirotiloDocumentsRetention DBExported" after the line that defines the variable myFolder.



  3. After the line myDoc.Close SaveChanges:=False add the following lines:



        FileCopy myDoc, exportedFolder & "" & strFile 'copy word file to Exported folder
    Kill myDoc 'deletes the word file



Make a backup of the Word files on C:UserszsirotiloDocumentsRetention DBInterviews before testing because it will delete the files.







share|improve this answer














share|improve this answer



share|improve this answer








edited Aug 20 '15 at 14:07

























answered Aug 20 '15 at 13:42









jcbermujcbermu

15.7k24355




15.7k24355













  • The issue is that I inhereted master excel sheet with data and 1) with ActiveSheet.Clear in macro it overrides all previous records with new ones AND 2) without ActiveSheet.Clear - it creates duplicates of previous records everytime the macro is ran, since it looks for Word docs in the specified folder.

    – YoniH
    Aug 20 '15 at 13:48











  • @YoniH I modified my answer to avoid the duplicates.

    – jcbermu
    Aug 20 '15 at 14:08











  • Thanks, I get debugger when I add as follows: myFolder = "C:UserszsirotiloDocumentsRetention DBInterviews" ExportedFolder = "C:UserszsirotiloDocumentsRetention DBInterviews - Exported" and then myDoc.Close SaveChanges:=False FileCopy myDoc, ExportedFolder & "" & strFile Kill myDoc

    – YoniH
    Aug 20 '15 at 14:28













  • @YoniH Do you mean an error? If the Word files are read only killwill fail

    – jcbermu
    Aug 20 '15 at 14:39











  • Sorry, I meant debugger error. The word docs are protected (they are generated from the restricted word form template). Debugger error picks up this expression FileCopy myDoc, ExportedFolder & "" & strFile

    – YoniH
    Aug 20 '15 at 14:43





















  • The issue is that I inhereted master excel sheet with data and 1) with ActiveSheet.Clear in macro it overrides all previous records with new ones AND 2) without ActiveSheet.Clear - it creates duplicates of previous records everytime the macro is ran, since it looks for Word docs in the specified folder.

    – YoniH
    Aug 20 '15 at 13:48











  • @YoniH I modified my answer to avoid the duplicates.

    – jcbermu
    Aug 20 '15 at 14:08











  • Thanks, I get debugger when I add as follows: myFolder = "C:UserszsirotiloDocumentsRetention DBInterviews" ExportedFolder = "C:UserszsirotiloDocumentsRetention DBInterviews - Exported" and then myDoc.Close SaveChanges:=False FileCopy myDoc, ExportedFolder & "" & strFile Kill myDoc

    – YoniH
    Aug 20 '15 at 14:28













  • @YoniH Do you mean an error? If the Word files are read only killwill fail

    – jcbermu
    Aug 20 '15 at 14:39











  • Sorry, I meant debugger error. The word docs are protected (they are generated from the restricted word form template). Debugger error picks up this expression FileCopy myDoc, ExportedFolder & "" & strFile

    – YoniH
    Aug 20 '15 at 14:43



















The issue is that I inhereted master excel sheet with data and 1) with ActiveSheet.Clear in macro it overrides all previous records with new ones AND 2) without ActiveSheet.Clear - it creates duplicates of previous records everytime the macro is ran, since it looks for Word docs in the specified folder.

– YoniH
Aug 20 '15 at 13:48





The issue is that I inhereted master excel sheet with data and 1) with ActiveSheet.Clear in macro it overrides all previous records with new ones AND 2) without ActiveSheet.Clear - it creates duplicates of previous records everytime the macro is ran, since it looks for Word docs in the specified folder.

– YoniH
Aug 20 '15 at 13:48













@YoniH I modified my answer to avoid the duplicates.

– jcbermu
Aug 20 '15 at 14:08





@YoniH I modified my answer to avoid the duplicates.

– jcbermu
Aug 20 '15 at 14:08













Thanks, I get debugger when I add as follows: myFolder = "C:UserszsirotiloDocumentsRetention DBInterviews" ExportedFolder = "C:UserszsirotiloDocumentsRetention DBInterviews - Exported" and then myDoc.Close SaveChanges:=False FileCopy myDoc, ExportedFolder & "" & strFile Kill myDoc

– YoniH
Aug 20 '15 at 14:28







Thanks, I get debugger when I add as follows: myFolder = "C:UserszsirotiloDocumentsRetention DBInterviews" ExportedFolder = "C:UserszsirotiloDocumentsRetention DBInterviews - Exported" and then myDoc.Close SaveChanges:=False FileCopy myDoc, ExportedFolder & "" & strFile Kill myDoc

– YoniH
Aug 20 '15 at 14:28















@YoniH Do you mean an error? If the Word files are read only killwill fail

– jcbermu
Aug 20 '15 at 14:39





@YoniH Do you mean an error? If the Word files are read only killwill fail

– jcbermu
Aug 20 '15 at 14:39













Sorry, I meant debugger error. The word docs are protected (they are generated from the restricted word form template). Debugger error picks up this expression FileCopy myDoc, ExportedFolder & "" & strFile

– YoniH
Aug 20 '15 at 14:43







Sorry, I meant debugger error. The word docs are protected (they are generated from the restricted word form template). Debugger error picks up this expression FileCopy myDoc, ExportedFolder & "" & strFile

– YoniH
Aug 20 '15 at 14:43




















draft saved

draft discarded




















































Thanks for contributing an answer to Super User!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f960170%2fneed-macro-to-transfer-word-data-into-excel%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

VNC viewer RFB protocol error: bad desktop size 0x0I Cannot Type the Key 'd' (lowercase) in VNC Viewer...

Tribunal Administrativo e Fiscal de Mirandela Referências Menu de...

looking for continuous Screen Capture for retroactivly reproducing errors, timeback machineRolling desktop...