我正在運行很少的宏來計算B列中文本的單詞,字符,段落和其他內容。但是,B列中的一些文本是超鏈接。由於多個超鏈接而讀取超鏈接後,未從另一個表中獲取總數
輸出片材:
現在,我的代碼(下面),該開口的超級鏈接和在不同的片的網站數據爬行回Excel(圖像02)。
在數據片中,計數多少字,字符,段落和其他的文本的再總結一切融合在一起(第一,通過柱;然後用單詞,字符,段落,和等。)並將值傳輸到輸出工作表。
然而,對於在輸出表中讀取列B中的超鏈接Display_Stylometric_Scores_Text循環,它會讀取並處理所有的超鏈接,但只給了我最後的超鏈接的正確傳輸值。
並非所有的結果才能被正確傳送:
我使用所謂的textRow一個變量來跟蹤文本的哪一行的,它是閱讀。我曾嘗試將TextRow = textRow + 1放入For循環中,希望它會讀取第一個超鏈接並將總計傳回到輸出表,但是當我這樣做時,它無法正確處理任何超鏈接。在這個例子中,第一個超鏈接是在第24行textRow = 24.
我想我的問題是:我仍然可以使用For循環逐行讀取超鏈接(更新textRow),只會去下一行或下一個超鏈接是否輸出了前一個超鏈接的正確總數?
代碼包括:
Sub Display_Stylometric_Scores_Text()
Dim Words As String
Dim Characters As String
Dim Paragraphs As String
Dim Sentences As String
Dim Sentences_per_paragraph As String
Dim Words_per_sentence As String
Dim Characters_per_word As String
Dim Ratio_of_passive_sentences As String
Dim Flesch_Reading_Ease_score As String
Dim Flesch_Kincaid_Grade_Level_score As String
Dim Coleman_Liau_Readability_Score As String
Dim Ampersands As Long
Dim Exclamations As Long
Dim ActiveDocument As Object
Dim RS As Object
Dim link As Hyperlink
Dim path As String
textRow = 24
path = Dir("C:\Users\Jeannette\Desktop\*.txt")
Set ActiveDocument = CreateObject("Word.Document")
Do While Worksheets("Sample_Output_2").Cells(textRow, 1) <> ""
textValue = Worksheets("Sample_Output_2").Cells(textRow, 2).Value
ActiveDocument.Content = textValue
Set RS = ActiveDocument.Content.ReadabilityStatistics
For Each link In Worksheets("Sample_Output_2").Cells(textRow, 2).Hyperlinks
activeWorkbook.Worksheets.Add
With ActiveSheet.QueryTables.Add(Connection:="URL;" & textValue, Destination:=Range("$A$1"))
.Name = "Text From URL"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
ActiveSheet.Activate
Call Display_Stylometric_Scores_URL
Worksheets("Sample_Output_2").Cells(textRow, 4).Value = ActiveSheet.Cells(finalRow, 4).Value
Worksheets("Sample_Output_2").Cells(textRow, 5).Value = ActiveSheet.Cells(finalRow, 5).Value
Worksheets("Sample_Output_2").Cells(textRow, 6).Value = ActiveSheet.Cells(finalRow, 6).Value
Worksheets("Sample_Output_2").Cells(textRow, 7).Value = ActiveSheet.Cells(finalRow, 7).Value
Worksheets("Sample_Output_2").Cells(textRow, 8).Value = ActiveSheet.Cells(finalRow, 8).Value
Worksheets("Sample_Output_2").Cells(textRow, 9).Value = ActiveSheet.Cells(finalRow, 9).Value
Worksheets("Sample_Output_2").Cells(textRow, 10).Value = ActiveSheet.Cells(finalRow, 10).Value
Worksheets("Sample_Output_2").Cells(textRow, 11).Value = ActiveSheet.Cells(finalRow, 11).Value
Worksheets("Sample_Output_2").Cells(textRow, 12).Value = ActiveSheet.Cells(finalRow, 12).Value
Worksheets("Sample_Output_2").Cells(textRow, 13).Value = ActiveSheet.Cells(finalRow, 13).Value
Worksheets("Sample_Output_2").Cells(textRow, 14).Value = ActiveSheet.Cells(finalRow, 14).Value
Worksheets("Sample_Output_2").Cells(textRow, 15).Value = ActiveSheet.Cells(finalRow, 15).Value
textRow = textRow + 1
Next link
謝謝!
代碼太多,清晰度太差,沒有數據樣本... – 2013-03-03 19:35:52
對不起,我沒有太多的清晰度,我編輯了這個問題,添加了一些我想要的代碼。我希望這很好的幫助。 – 2013-03-03 21:18:05
@JeannetteLiu:即使有截圖,也很難理解你的情況和問題!你的第一句話已經意味着關於我們沒有的問題的很多知識!如果你想要一些答案,請重新說明! – 2013-03-03 21:25:33