473,396 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Need code help to update activesheet in .xls

Hello,
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.
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.
Your help is appreciated!

Expand|Select|Wrap|Line Numbers
  1. Sub getWordFormData()
  2. Dim wdApp As New Word.Application
  3. Dim myDoc As Word.Document
  4. Dim CCtl As Word.ContentControl
  5. Dim myFolder As String, strFile As String
  6. Dim myWkSht As Worksheet, i As Long, j As Long
  7.  
  8. myFolder = "C:\Users\username\Documents\Retention DB\Interviews"
  9. Application.ScreenUpdating = False
  10.  
  11. If myFolder = "" Then Exit Sub
  12. Set myWkSht = ActiveSheet
  13. ActiveSheet.Cells.Clear
  14.  
  15. Range("A1") = "Company Name"
  16. Range("A1").Font.Bold = True
  17. Range("B1") = "Type of Company"
  18.  
  19. i = myWkSht.Cells(myWkSht.Rows.Count, 1).End(xlUp).Row
  20. strFile = Dir(myFolder & "\*.docx", vbNormal)
  21.  
  22. While strFile <> ""
  23. i = i + 1
  24.  
  25. Set myDoc = wdApp.Documents.Open(Filename:=myFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
  26.  
  27. With myDoc
  28. j = 0
  29. For Each CCtl In .ContentControls
  30. j = j + 1
  31. myWkSht.Cells(i, j) = CCtl.Range.Text
  32. Next
  33. myWkSht.Columns.ColumnWidth = 25
  34. End With
  35. myDoc.Close SaveChanges:=False
  36. strFile = Dir()
  37. Wend
  38. wdApp.Quit
  39. Set myDoc = Nothing: Set wdApp = Nothing: Set myWkSht = Nothing
  40. Application.ScreenUpdating = True
  41.  
  42. End Sub
  43.  
Aug 19 '15 #1
0 1017

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Larry Woods | last post by:
I have a datagrid that is carrying all fields of a record...except one. Now I want to update the underlying database via a dataadapter. The update is working but the field that is "left out" is...
2
by: Richard | last post by:
Hi, I have 1 dataset with 2 tables (Table1 as parent, Table2 as Child), 1 row in both the tables. I am updating it with a transaction. First parent then child. When child update fails, it raise...
1
by: Mark Smith | last post by:
Hi, I have the capture from http stream which is chunked and gzipped. I need code to de-chunk it (i.e. decode it), and then gunzip it--just like a web browser woudl do. Could someone please help...
6
by: Tark Siala | last post by:
hi i spend more time to write the code, like VB6, VB2005, SQL Stored Procedure code. any one know good Application to Automaticaly read Database (Access or SQL), then write VB Code and Stored...
4
by: not_a_commie | last post by:
I need code to peg the CPU for 10 seconds to test some background threads. Sleep obviously doesn't do that. How do I code a busy loop that won't get removed by the compiler? Thanks.
1
by: davidkurniawan | last post by:
Thanks b4 I need code for Hibernate, Log off, Shutdown Computer using API programming in VB.net for XP Vista and another Version Windows Operating System Is it Possibble ? david kurniawan...
2
by: shinerankin | last post by:
Hi Guys & Gals: I have a project with using flash that is updated with an xml file. The developer went belly up and is no longer assisting with anything. I need to write a simple html or php form...
1
by: evilbungle | last post by:
Good Morning, Hopefully someone can help me with what I am assuming is a simple query that I simply can't get to work. I am new to using Visual Basic and I am using Visual Studio 2005,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.