Advertisement

10.13.2008 at 03:05PM PDT, ID: 23811055
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.7

Macro Error  -> "Removed rows from SpreadSheet - now the Macro to extract the data to a Word does not work

Asked by nedbacan in Microsoft Excel Spreadsheet Software, Microsoft Development

Tags: , , , , ,

I have a macro that extracts data from an Excel sheet and into a Word ducument table. It was working fine until I removed serveral rows from the spreadsheet, now it complaints about the following line;
'delete the last row which will be blank
    Selection.Tables(1).Rows(Selection.Information(wdEndOfRangeRowNumber)).Delete

Don't know how to trouble shoot this, need help in getting the macro to run again with the new format of the spreadsheet (see the  "new format" folder)

Attached, are the sample folders to run the test.
-> old-format.zip - this folder contains the old format of the spreadsheet. This format works well with the macro saved in the "Import-CodeReview-Comments (original).doc" . The macro is auto runned when the doc is opened.
-> new-format.zip- this folder contains the new format done in the spreadsheet.

Instructions:  In order to see the macro run with the with the old format, the old format or new format folder need to be created on the root drive which is c:\  
(i.e c:\old format or c:\new format)

Which lead to another question, how can I stop from having to change the path in the Macro to find where the excel sheet ared saved.  
Can I just give it a default folder name (relative path) and not worry about the drive letter or the root folder.
(i.e  "..\code review" or "..\test\code review\" ).

Thank you in advance.






 Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
Sub ImportComments()
 
'Excel source file folder
Dim strExcelFolder As String
strExcelFolder = "c:\new format\"
 
'get the first excel file name
Dim strExcelFile As String
strExcelFile = Dir(strExcelFolder & "*.xls", vbNormal)
 
'if no files in the folder then exit routine
If strExcelFile = "" Then Exit Sub
 
'create Excel object
Dim objXL As Object
Set objXL = CreateObject("Excel.Application")
 
'define Excel object variables
Dim r As Integer        'row
Dim c As Object         'cell
Dim objWB As Object     'workbook
Dim objWS As Object     'worksheet
 
'while there are excel files to parse
While strExcelFile <> ""
 
    'set the workbook and worksheet objects
    Set objWB = objXL.Workbooks.Open(strExcelFolder & strExcelFile)
    Set objWS = objWB.Sheets(1)
 
    'set the intial row offset value
    r = 1
 
    'find the first row to start the import from
    Set c = objWS.Cells.Find(What:="Review Comments", After:=objXL.ActiveWindow.ActiveCell, LookIn:=-4163, _
        LookAt:=1, SearchOrder:=1, SearchDirection:=1, _
        MatchCase:=True, SearchFormat:=False)
 
    'if the starting cell is found
    If Not c Is Nothing Then
 
        'copy the defined cell range
        objWS.Range("B6:C16").Copy
        'paset the cell range into Word
        Selection.PasteExcelTable False, False, True
 
        'structure the pasted cell data table as desired
        Selection.MoveLeft wdCharacter
        With Selection.Tables(1)
           'sinlge spaced lines
            With .Range.ParagraphFormat
                .SpaceBefore = 0
                .SpaceAfter = 0
                .LineSpacingRule = wdLineSpaceSingle
            End With
            'desired width for each column
            .Columns(1).PreferredWidth = InchesToPoints(2.24)
            .Columns(2).PreferredWidth = InchesToPoints(2.29)
        End With
 
        'create starting point and table for comment data
        Selection.EndKey wdStory
        Selection.TypeParagraph
 
       'create table
        ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=2, NumColumns:=2
        With Selection.Tables(1)
            .Borders.InsideLineStyle = wdLineStyleSingle
            .Borders.OutsideLineStyle = wdLineStyleSingle
            With .Cell(1, 1).Range
                .Text = "Comments"
                .Font.Bold = True
            End With
            With .Cell(1, 2).Range
                .Text = "Recommended Action"
                .Font.Bold = True
            End With
            .Cell(2, 1).Select
        End With
 
        'if the starting point has some shading applied
        If c.Interior.Pattern <> -4142 Then
 
           'cycle through each row until a COUNTIF formula is found to the cell one column to the left
            While InStr(1, c.Offset(r, -1).Formula, "=countif", vbTextCompare) = 0
 
                'if No column is checked off
                If c.Offset(r, -2) <> "" Then
                    'enter the comment
                    Selection.TypeText c.Offset(r, 0).Value
                    Selection.MoveRight wdCell
                    'enter the recommended action
                    Selection.TypeText c.Offset(r, 1).Value
                    Selection.MoveRight wdCell
                End If
                'increment offset row
                r = r + 1
            Wend
        End If
    End If
 
    'reset cell varaible
    Set c = Nothing
 
    'delete the last row which will be blank
    Selection.Tables(1).Rows(Selection.Information(wdEndOfRangeRowNumber)).Delete
 
    'close the workbook without savign changes
    objWB.Close 2
 
    'get the next ecxcel file to parse
    strExcelFile = Dir
 
    'if there is a file to parse start a new page
    If strExcelFile <> "" Then Selection.InsertBreak
 
Wend
 
'close the excel application object
objXL.Quit
 
'resst all excel object variables
Set objXL = Nothing
Set objWS = Nothing
Set objWB = Nothing
 
End Sub
Attachments:
 
This is the version that extract the data (save it in "c:\old format" folder)
 
 
This is the version that gives an error when extracting the data. (save it in "c:\new format" folder)
 
[+][-]10.13.2008 at 05:49PM PDT, ID: 22707836

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.13.2008 at 06:26PM PDT, ID: 22707984

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.14.2008 at 07:28AM PDT, ID: 22711580

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.14.2008 at 01:44PM PDT, ID: 22715815

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.14.2008 at 02:00PM PDT, ID: 22715937

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.14.2008 at 04:42PM PDT, ID: 22717011

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.15.2008 at 08:32AM PDT, ID: 22722288

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.15.2008 at 08:38AM PDT, ID: 22722354

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.16.2008 at 06:35AM PDT, ID: 22730630

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Excel Spreadsheet Software, Microsoft Development
Tags: Microsoft, Word, 2003, VB Macros, VB, Run Time error '5941': Requested member of the collection does not exist
Sign Up Now!
Solution Provided By: epaclm
Participating Experts: 1
Solution Grade: A
 
 
[+][-]10.16.2008 at 06:42AM PDT, ID: 22730706

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.16.2008 at 06:44AM PDT, ID: 22730725

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-42 - Hierarchy / EE_QW_2_20070628