用于在记事本

时间:2016-12-29 10:44:32

标签: excel vba excel-vba

我在Excel中的范围如下:

Range("S15").Select Range(Selection, Selection.End(xlDown)).Select,我必须使用宏在记事本中自动保存此范围。

我已经有了这段代码:

Option Explicit

Sub Step_6_test()

Dim FilePath As String
Dim CellData As String
Dim LastCol As Long
Dim LastRow As Long

LastCol = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Column
LastRow = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row

CellData = ""
FilePath = Application.DefaultFilePath & "\auth.csv"

Open FilePath For Output As #2

For i = 1 To LastRow

    For j = 1 To LastCol
        If j = LastCol Then
            CellData = CellData + Trim(ActiveCell(i, j).Value)
        Else
            CellData = CellData + Trim(ActiveCell(i, j).Value) + ","
        End If
    Next j

    Write #2, CellData
    CellData = ""
Next i

Close #2
MsgBox ("Done")

End Sub

但是此代码用于将其保存在Excel文本文件中,但我想自动在记事本中保存我的范围。 如何在记事本中更改用于保存范围的代码?

1 个答案:

答案 0 :(得分:1)

跟进@Limak评论,只需将文件另存为string x; var list2 = (List<string>)Session["title"]; if (list2 == null) { x = "No new Products Found"; } else { x = string.Join(",", list2); // x= list2[0]; } //foreach (string x in list2) //{ // Your code for(int i=0;i<3;i++) { var oauth_consumer_key = "[REDACTED]"; var oauth_consumer_secret = "[REDACTED]"; if (Request["oauth_token"] == null) { OAuthTokenResponse reqToken = OAuthUtility.GetRequestToken( oauth_consumer_key, oauth_consumer_secret, Request.Url.AbsoluteUri); if(reqToken !=null) { Session["reqToken"] = reqToken; } string mx = Session["reqToken"].ToString(); Response.Redirect(string.Format("http://twitter.com/oauth/authorize?oauth_token={0}", reqToken.Token)); } else { string fx = Session["reqToken"].ToString(); string requestToken = Request["oauth_token"].ToString(); string pin = Request["oauth_verifier"].ToString(); var tokens = OAuthUtility.GetAccessToken( oauth_consumer_key, oauth_consumer_secret, requestToken, pin); if(tokens!=null) { Session["tokens"] = tokens; } //var tokens = OAuthUtility.GetAccessToken( //oauth_consumer_key, //oauth_consumer_secret, //requestToken, //pin); OAuthTokens accesstoken = new OAuthTokens() { AccessToken = tokens.Token, AccessTokenSecret = tokens.TokenSecret, ConsumerKey = oauth_consumer_key, ConsumerSecret = oauth_consumer_secret }; //TwitterResponse<TwitterStatus> response = TwitterStatus.Update( // accesstoken, // "Testing!! It works (hopefully)."); Twitterizer.TwitterResponse<TwitterStatus> response = TwitterStatus.Update(accesstoken, x, new StatusUpdateOptions() { UseSSL = true, APIBaseAddress = "http://api.twitter.com/1.1/" }); if (response.Result == RequestResult.Success) { // Response.Redirect("https://twitter.com/"); } else { // Response.Redirect("https://twitter.com/"); } } } }

另外,您有.txt,但是您没有在循环中推进CellData = CellData + Trim(ActiveCell(i, j).Value)(您需要使用ActiveCell)。相反,您可以使用ActiveCell

完整代码

CellData = CellData + Trim(Cells(i, j).Value)