2016-07-06 5 views
1

私は2つのサブを持っています。最初のサブキー(GetKeyWord)はユーザーにキーワードを尋ね、文字列配列に格納します。次のサブ(AlertFinder)は特定の文字列配列を取り込み、それをWebページで検索します。しかし、AlertFinderをx分ごとに実行したいのですが、AlertFinderが実行されるたびにどのキーワードを探しているのかをユーザーに尋ねることは望ましくありません(最初にユーザーに一度だけ質問し、その後も配列は一定にとどまる)。これがGetKeyWordを別のサブにした理由ですが、GetKeyWordの文字列配列を実行するためにAlertFinderを実行するのに問題があります。VBA定期的なサブに変数を渡す

Sub GetKeyWords() 


Dim numKey As Integer 
Dim strTemp() As Variant 

'Input Keywords 

numKey = InputBox("How many keywords would you like to search for? (Integer)", "Integer Value Please") 




For k = 1 To numKey 
    ReDim Preserve strTemp(numKey - 1) 
    strTemp(k - 1) = InputBox("Please enter keyword" & k) 


Next 


'Execute Alert Finder 
Call AlertFinder(strTemp) 
End Sub 


Sub AlertFinder(strTemp() As Variant) 


'Set Variables 
Dim boolFound As Boolean 
Dim txt As String 
Dim strOutput As String 
Dim tbl As HTMLTable, tables As IHTMLElementCollection 
Dim tr As HTMLTableRow, r As Integer, i As Integer 
Dim tRows As IHTMLElementCollection 
Dim ie As InternetExplorer 
Dim strCurrent As Variant 

~bunch of code~ 

    Set ieDoc = ie.Document 

    'Loop to refresh webpage every 25 minutes 
    Do While True 

     'Pause the script for x minutes 
     Application.Wait (Now + TimeValue("00:05:00")) 

     'AFter time is up, reload page and run Alert Finder Again 
     ieDoc.Location.Reload (True) 
     AlertFinder (strTemp) 

     If Err <> 0 Then 

      Wscript.Quit 
     End If 
    Loop 

    Set ie = Nothing 
    End Sub 

私はAlertFinder自体の中AlertFinder(strTemp)を呼び出そうどこトラブルが生じたが、strTempはGetKeyWordから来て、私はすべてのGetKeyWordを実行する必要があり、一定のままとしないようにしたい。ここでは

コードです5分。どんな助けもありがとう!

+0

"〜束のコード〜"が見えないと分かりにくいですが、再帰を使う代わりに 'Sub AlertFinder'からループを' Sub'に抽出してください。 – Comintern

+0

ありがとうございます!精巧にお考えですか? –

+0

ループがスクリプトを有効にしています。 'AlertFinder(strTemp)'をもう一度呼び出す理由はありません。起こっていることは、5分ごとにAlertFinderの別のコピーを作成することです。 5分でAlertFinderが2部、10分で4部、15分で16部...などがあります。 –

答えて

0

コメントした人に感謝します。私がやったことは、StrTempをPublic変数として宣言し、GetKeywordに値を渡してAlertFinderに渡すことでした.AlertFinderはそれ自身を呼び出すこともできました(GetKeywordサブで宣言されているstrTemp()のインスタンスをすべて削除)。うまく働いた。バリアント

として

公開strTemp()すべてのサブプロシージャーは、トリックをした前に。これは誰もが同じ問題を抱えていることを願っています。

関連する問題