VBA or Macro Help: Create new files based on dynamic text in a tab

I have 7 tables in a Word doc.  Each table has a cell for "Owner".  Suzy is 
the owner in 4 of the tables, John is the owner in 3.  I want to loop through 
all possible owners (in this case, 2), find each table that belongs to them, 
and create a new file for each owner.  At the end of the macro, I'd have a 
file called "Suzy.doc" with her 4 tables appended and one called "John.doc" 
with his 3 tables appended.  I could code this back in the day by looping 
through a 'getOwner-readWordDoc-testCondition-writeRecord' loop-until-end.  
But, I can't figure out how to do this in a macro or VBA.  Anyone have any 
ideas?  I've got a mock-up Word doc I can send as an example.
-- 
JenInCO
0
Utf
1/14/2010 12:37:03 AM
word.vba.general 1023 articles. 1 followers. Follow

2 Replies
1380 Views

Similar Articles

[PageSpeed] 2

Hi,

If the cell containing the owner is located in the same position (row number 
and column number) in each table, you could loop through the collection of 
tables, check the contents of that cell, and add the table to the applicable 
document.
This can be done with code such as the following, which uses the first cell 
in each table.

Dim myTable As table
With ActiveDocument
    For Each myTable In .Tables
        Select Case Left(myTable.Cell(1, 1).Range.Text, _
            Len(myTable.Cell(1, 1).Range.Text) - 2)
            Case "Suzy"
                ' Add code to insert myTable into Suzy.doc
            Case "John"
                ' Add code to insert myTable into John.doc
            ' Add Case statements for other owners.
            Case Else
                ' Add code for default action.
         End Select
    Next
End With

Write back if this is suitable for your purposes and you need more help.

-- 
Hope this helps,
Pesach Shelnitz
My Web site: http://makeofficework.com 


"JenInCO" wrote:

> I have 7 tables in a Word doc.  Each table has a cell for "Owner".  Suzy is 
> the owner in 4 of the tables, John is the owner in 3.  I want to loop through 
> all possible owners (in this case, 2), find each table that belongs to them, 
> and create a new file for each owner.  At the end of the macro, I'd have a 
> file called "Suzy.doc" with her 4 tables appended and one called "John.doc" 
> with his 3 tables appended.  I could code this back in the day by looping 
> through a 'getOwner-readWordDoc-testCondition-writeRecord' loop-until-end.  
> But, I can't figure out how to do this in a macro or VBA.  Anyone have any 
> ideas?  I've got a mock-up Word doc I can send as an example.
> -- 
> JenInCO
0
Utf
1/14/2010 1:51:02 PM
Thank you Pesach.  I will try this as soon as possible and let you know.
-- 
JenInCO


"Pesach Shelnitz" wrote:

> Hi,
> 
> If the cell containing the owner is located in the same position (row number 
> and column number) in each table, you could loop through the collection of 
> tables, check the contents of that cell, and add the table to the applicable 
> document.
> This can be done with code such as the following, which uses the first cell 
> in each table.
> 
> Dim myTable As table
> With ActiveDocument
>     For Each myTable In .Tables
>         Select Case Left(myTable.Cell(1, 1).Range.Text, _
>             Len(myTable.Cell(1, 1).Range.Text) - 2)
>             Case "Suzy"
>                 ' Add code to insert myTable into Suzy.doc
>             Case "John"
>                 ' Add code to insert myTable into John.doc
>             ' Add Case statements for other owners.
>             Case Else
>                 ' Add code for default action.
>          End Select
>     Next
> End With
> 
> Write back if this is suitable for your purposes and you need more help.
> 
> -- 
> Hope this helps,
> Pesach Shelnitz
> My Web site: http://makeofficework.com 
> 
> 
> "JenInCO" wrote:
> 
> > I have 7 tables in a Word doc.  Each table has a cell for "Owner".  Suzy is 
> > the owner in 4 of the tables, John is the owner in 3.  I want to loop through 
> > all possible owners (in this case, 2), find each table that belongs to them, 
> > and create a new file for each owner.  At the end of the macro, I'd have a 
> > file called "Suzy.doc" with her 4 tables appended and one called "John.doc" 
> > with his 3 tables appended.  I could code this back in the day by looping 
> > through a 'getOwner-readWordDoc-testCondition-writeRecord' loop-until-end.  
> > But, I can't figure out how to do this in a macro or VBA.  Anyone have any 
> > ideas?  I've got a mock-up Word doc I can send as an example.
> > -- 
> > JenInCO
0
Utf
1/14/2010 10:23:02 PM
Reply:

Similar Artilces:

Invalid Account on the Security Tab
I deleted an account from AD, and it was listed under the security tab of my server (in ESM), to have full mailbox rights to the information store. I tried removing the inherited permissions, and removing the acct. The I set the inherited permissions back, and the invalid acct. comes back. Does anyone know how I can remove this invalid acct. from the security tab? Thanks. Remove it from the top-level where it was granted permissions. When you set inherited permissions and the account comes back, that means that that account has been granted permissions at a higher level. If you'v...

Autonumber created.. problems in the future?
I managed to create an autonumber in Microsoft CRM. I did this by making a field "Number"(in the database "New_Number") and I published it on the form. Then I went To the SQL server and I changed the field in the table to Identity Yes, Identity seed 1, Identity Increment 1. I locked the field on the form. It worked! I think that this is not supported by Microsoft. But has anybody got any idea which troubles i could get with this configuration? San ________________________________ Do you know all add-ons for Microsoft CRM? Visit http://www.pimpmycrm.com The biggest dange...

File size #11
I have read the other discussions on file sizes but they do not seem to address my problem. I have an Excel file that is 12mb large with low-res jpegs in it. This file also has merged cells to make it look pretty. Does Excel look at these merged cells as graphics? Is this why they are too big? I have run a macro to make sure that it goes to the last cell. How can I get the file smaller? How big are the graphics? If you remove them from the file, what is the size of the file and what is the size of the graphic files? To be sure you do not have extra formatting, if you open the file...

find action on log file
Hello there I want to use outside tool to find who made some update on table in my server I know that there are many tools for this. But can they do it on simple recovery model? Roy Goldhammer (royg@yahoo.com) writes: > I want to use outside tool to find who made some update on table in my > server > > I know that there are many tools for this. But can they do it on simple > recovery model? No. If you are using the simple recovery model, the contents of the log is wasted away everyonce in a while. Well, if the disk area has not been overwritten...

Maximum file sizes
Is there a recommended maximum file size for Excel 2000. PC spec 2Ghz P4 with 256 Mb Any advice appreciated Deus -------------- Does Not Exist Hi have a look at http://www.decisionmodels.com/memlimits.htm -- Regards Frank Kabel Frankfurt, Germany "Deus DNE" <deus.dne@ntlworld.com> schrieb im Newsbeitrag news:1561701c41d4f$358950f0$a001280a@phx.gbl... > Is there a recommended maximum file size for Excel 2000. > > PC spec 2Ghz P4 with 256 Mb > > Any advice appreciated > > Deus > -------------- > Does Not Exist ...

Looking for Excel Help
I'm a very novice Excel user and am looking for a little help with creating a formula for a spreadsheet I'm creating for my personal use. I would appreciate some assistance if possible. Thanks in advance. Dan --- Message posted from http://www.ExcelForum.com/ Hi Dan! Post a sample of what you want to do. Your question is just a tad open ended <g> -- Regards Norman Harker MVP (Excel) Sydney, Australia njharker@optusnet.com.au Excel and Word Function Lists (Classifications, Syntax and Arguments) available free to good homes. "DanB4105" <DanB4105.ywtpa@excelfor...

New to excel
Hi All, I'm new to Excel ( and to this forum :) ) and so I hope somebody may b able to help me. I've got 2 questions.... QUESTION 1 I've got a spreadsheet which takes data from one worksheet and uses i to calculate data in a second worksheet using the following code formula: =IF('4th November 2005'!B19="","nothing here dude",IF(B19<'4th Novembe 2005'!B19,"UP",IF(B19='4th November 2005'!B19,"Same",IF(B19>'4t November 2005'!B19,"DOWN")))) The problem is, when I create a new worksheet I have...

Attaching Contacts to new email
Creating a new email. When contacts folder has "shared" contacts and "personal" contacts how can you set your personal contacts as the default? Example: creating a new email having never addressed the "send to" contact before, you hit the "To" button. Currently my "shared" contacts opens up but I would like my "personal" contacts page to open instead of having to drop down to "contacts" to bring up that list. Is there a solution to this? Thank you!!! On 2/26/2010 10:21 AM, assistantneedshelp wrote: >...

How to repair a .dll file in IE8
Several days ago I noticed in my Dependency Walker that the IESHIMS.dll files has a yellow circle with a question mark on it. What does this mean and How do I repair it? OS: Windows Vista Home Premium Browser Internet Explorer 8 -- TW Hi, See the History tab on that dialog. A web search for ieshims.dll files will also help you find a solution for that file. Regards. "TW" <TW@discussions.microsoft.com> wrote in message news:63E61463-D766-4ABC-B081-BFA8C04FB159@microsoft.com... > Several days ago I noticed in my Dependency Walker that the IESHIMS....

Using Relative path for XML data file?
Is there a way to specify a relative path to an XML data file imported into Excel 2003? I am writing a web app that generates report data as XML for the user to download to their local machine. This data is to be consumed by an Excel reporting spreadsheet, which contains display-formatted tables and charts that are mapped to various data fields in an XML Map, which is in turn linked to the xml data file they will download. The idea is the user only needs to download the data for updates, not the whole spreadsheet. However, since I cannot predict the path where the user will store their...

unsolicited entry in the folder "Temporary Internet Files"
Hello, I am working on a programme which browses web sites and runs under XP. The http download is as follows: pServer = Isession -> GetHttpConnection(strServerName, nPort); pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_GET, strObject, NULL, 1, NULL, NULL, dwHttpRequestFlags); pFile->SendRequest(); pFile->QueryInfoStatusCode(dwStatusCode); if(dwStatusCode == 200) { pFile -> QueryInfo(HTTP_QUERY_LAST_MODIFIED, &sysT); status.lastMod = sysT; if(DBlastMod == status.lastMod) //URL content has not changed since the last visit ...

New Implementation
I have following queries regarding new implementation: 1) If I ask that I have 8 outlets at remote locations & these are all garments stores, which will communicate with HQ Server. Each store is having around 1500 items. Now the question is how much time/days will it required to implement? Can anyone tell me an approximate time period? Just have an idea. 2) Which connection/line is fast/speedy for communication with HQ server from remote stores? Like DSL, Dial ap. IS VPN necessary?If NOT Y and if YES Y?? 3) Initial Steps ======= •Will start from Store Operation Template Database. •Af...

how to convert lookup values to the "display text"
I'm using an sql code (below) which uses a few lookup fields. Unfortunately in the datasheet view, I get the "bound values" instead of the "display values". How can I change the properties for the these lookup fields so I can see the "display values" from the datasheet view? SELECT [Funding],[Date],[Description],[Company],[Expense_Type],[Amount],[Status] FROM [Form_9_Status] UNION ALL SELECT [Funding],[Date],[Description],[Company],[Expense_Type],[Amount],[Status] FROM [TDY_Status] UNION ALL SELECT [Funding],[Date],[Description],[C...

Linking files 2 ways
I have a work book that is linked to another and vise versa. As thus: Workbook A is where the input of data is made; Workbook B has a link to the input from workbook A; Workbook A retrieves the altered data back as a link. Although this all works fine with both books open, I note that if I open workbook A by itself, that the data it retrieves from Workbook B is not updated . If However, both books are open, there's no problem. I thought linked books were updated automatically if the Update remote references has been selected?? But it appears that the second book is not updated until it ...

OL2007 not move big files from outbox to sent
Hi, We have 2 computers with separate email accounts on Roadrunner. One machine has XP with Outlook 2002-sp3 and works without any problems. The other has Outlook 2007 on Vista and has problems sending files over a meg or so in size. It seems to actually send the file but the file remains in the outbox folder and does not move it to the sent folder. I say it "seems" to send the file because some people complain of getting muliple copies and others don't seem to get them at all. If I hit send again (not set up for auto send) it seems to send the file again (why some ...

explanation of codes in Visual Basic when creating User form
Hi, I am trying to create a user form in Visual Basic however I'm trying to teach myself by reading/watching tutorials. (www.contectures.o.ca, etc) A lot of the instructions I am seeing simply give the code rather than explain how to actually write one from scratch. So... I need to know what each 'term' means so I can understand how the codes work. Any help is much appreciated :) One of the first codes is for the Add button Private Sub cmdAdd_Click() Dim iRow As Long Dim ws As Worksheet Set ws = Worksheets("PartsData") What d...

Need Help, Task Start Date is wrong
I’m using MS Project 2007, have several task linked with finish to start. I have set date to schedule from, hours per day set to 8 and Working Monday thru Friday. My schedule shows Task 1 Duration 4 days, start Wed 6/2/10, Finish Mon 6/7/10 Task 2 Duration 3 days, start Mon 6/7/10, Finish Thu 6/10/10 Task 2 should have a Start Date of 6/8/10 not 6/7/10; what is causing this? Thanks in advance for your help. ...

I need a macro
I would like a macro to do the following: I would place the the cursor in any cell and this macro would give me the average of all the entries to the left if the selected cell. EX: I place the cursor in cell M12. I want this macro on display in cell M12 the average of all the values from Col C12 to Col L12. Note that there may NOT be entries in all the cells in that range. Also the start point would always be col C .Thanks You can do this easily with a worksheet_selection event in the sheet module but you would probably want to restrict to a certain range or columns and rows or it woul...

How to automate increasing the form cache registry/file etc...
I want to roll out a batch file to make a number of tweaks to CRM The body of it would go REGEDIT /S Kerberosefix.reg REGEDIT /S ForceFormreload.reg REGEDIT /S OutlookFix.reg It would also rename OSA.exe to OSA.bad Remove OSA.exe From the startup menu I need help finding a way to use my batch file to increase the Outlook Form cache from the default 4MB to 50 MB.. This makes CRm more stable and faster for communications. I dont want to manually do this, as it time consuming, are my end users would not be reliable in doing it themselves. I also want to make another batch file or button that...

New Record
I'm using the following in the On Click of a command button. DoCmd.GoToRecord acDataForm, "frmMyForm", acNewRec Anyway I can do this without referenceing the Object (Form) name?? James James, Yes... DoCmd.GoToRecord , , acNewRec God Bless, Mark A. Sam "JamesJ" <jjy@adelphia_darwin.net> wrote in message news:er2loxDPIHA.1208@TK2MSFTNGP03.phx.gbl... > I'm using the following in the On Click of a command button. > > DoCmd.GoToRecord acDataForm, "frmMyForm", acNewRec > > Anyway I can do this without referenceing the Object (Form)...

Certain Keys/Characters not recognised when creating a task
I've just attempted to create a task and the edit control for the subject of the task refused to accept the characters c h s t u and v. I was able to switch to other applications such as a command prompt and internet explorer and type the characters quite happily (so there is nothing wrong with the keyboard) but when I switch back to Outlook it will not recognise them. I'm using Outlook2003 as installed with Office 2003 Professional (SP1 and all other updates applied). As a last resort I closed down Outlook and restarted the program which is now accepting the keys/characters. A...

Setting a dynamic range in a formula
Hi, I have a column of numbers and I always want the following arra formula to use the last 12 entries: =(PRODUCT(1+D1:D12/100)-1)*100 Any suggestions? Thanks, Phillycheese -- Phillycheese ----------------------------------------------------------------------- Phillycheese5's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=2419 View this thread: http://www.excelforum.com/showthread.php?threadid=37809 Assuming that Column D contains no blanks, try... =(PRODUCT(1+OFFSET(D1,MAX(0,COUNTA(D:D)-12),0,12,1)/100)-1)*100 ...confirmed with CONTROL+SHIFT+ENTER. Hope th...

Please help #8
I have Exchange 2000 and Outlook 2003 in Cache mode. Has anyone seen this or know how to fix it? Task 'Microsoft Exchange Server' reported error (0x8007000E) : 'Out of memory or system resources. Close some windows or programs and try again.' "John S" wrote: > > I have Exchange 2000 and Outlook 2003 in Cache mode. Has anyone seen this or > know how to fix it? > > Task 'Microsoft Exchange Server' reported error (0x8007000E) : 'Out of > memory or system resources. Close some windows or programs and try again.' > >...

How do I see when new messages without outlook running?
Without Outlook 2003 constantly running, how do I send mail or know when I have new mail? two possible answers... 1) you don't or 2) you acquired a 3rd party app to occasionally poll your pop3/imap account "Leslie Adams" <Leslie Adams@discussions.microsoft.com> wrote in message news:D37C11C7-722C-4E91-9393-735A49C11701@microsoft.com... > Without Outlook 2003 constantly running, how do I send mail or know when I > have new mail? ...

Pulling data from separate tabs
When charting in Excel 2002 is there a way to use sets of data from two different tabs within the same worksheet? For example, a spreadsheet contains separate tabs for prior year and current year data. Is there a way to reference the data or label series to pick up data from both? I tried pointing and clicking, and then typing the following as a reference for the axis labels: ='Prior Year'!$B$110:$M$110,'Current Year'!'$B$110:$M$110 but receive an error that I'm referring to an external worksheet. I've used the comma (') in the past to reference breaks ...