用文本框replacesheet1作为日志数据值来创build请求文件VBA Excelmacros

大家好我有一个Excelmacros来创build一个请求文件。 这些请求文件是从Sheet1中列出的日志数据编号创build的。 我在这里使用了一个replace过程。 来自sheet2(ColumnA)的数据将replace我将在sheet1中保留所有整数的字母或string,并删除日志数据编号中的所有文本或string。

例:
如果我有H1PL12N0macros一旦执行,它将只成为12,并创build一个请求文件为h1p-12.req值或DM 我的macros正在工作。 我唯一担心的是使用Sheet1而不是使用TextBox。

因此,不需要在sheet1中键入或input日志数据编号,而是将其键入或input到我的用户窗体的文本框中。 我已经尝试search相同或相关的问题,但我找不到。

尝试分配或设置文本框到Sheet1的myDataSheet,但我得到一个错误,告诉对象所需。 我只是新的VBA,并试图使自己的macros观。 希望你能帮助我,提前谢谢你。

我的Excel宏的快照 inheritance人我的代码:

 Private Sub CREATE_REQ_Click() Dim myData As String Dim myReplaceSheet As Worksheet Dim myLastRow As Long Dim myRow As Long Dim myFind As String Dim myReplace1 As String Dim myReplace2 As String Dim sExportFolder, sFN Dim rArticleName As Range Dim rDisclaimer As Range Dim oSh As Worksheet Dim oFS As Object Dim oTxt As Object If project_list.Text = "" Then MsgBox "Please select a project! Thanks!" GoTo a11 End If If combo1.Value = "" Then MsgBox "Please select input ! Thanks!" GoTo a11 End If If ListBox1.Text = "" Then MsgBox "Please select the Block Name! Thanks!" GoTo a11 End If If TextBox1.Value = "" Then MsgBox "Please Key-in folder address ! Thanks!" GoTo a11 End If 'Specify name of Data sheet Set myData = TextBox2 Set myReplaceSheet = Sheets("Sheet2") myLastRow = myReplaceSheet.Cells(Rows.Count, "A").End(xlUp).Row Application.ScreenUpdating = False For myRow = 2 To myLastRow myFind = myReplaceSheet.Cells(myRow, "A") myReplace1 = myReplaceSheet.Cells(myRow, "B") myDataSheet.Select 'Range("A2").Select On Error Resume Next 'Do all replacements on column A of data sheet Columns("A:A").Replace What:=myFind, Replacement:=myReplace1, LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False Next myRow sExportFolder = TextBox1 ' "D:\TEST\REQ_FILES_CREATED_HERE" Set oSh = Sheet1 Set oFS = CreateObject("Scripting.Filesystemobject") For Each rArticleName In oSh.UsedRange.Columns("A").Cells 'Set rDisclaimer = combo1.Value.Select 'rArticleName.Offset(, 1) If Not (rArticleName = "" Or rArticleName = "LOG DATA") Then 'Add .txt to the article name as a file name sFN = "-" & rArticleName.Value & ".req" Set oTxt = oFS.OpenTextFile(sExportFolder & "\" & ListBox1 & sFN, 2, True) oTxt.Write combo1.Value oTxt.Close End If Next 'Reset error checking On Error GoTo 0 Application.ScreenUpdating = True MsgBox "REQUEST FILES CREATED!" a11: End Sub