[求助]求帮忙改写一下代码
<p>在excel中能正确运行的vba代码,怎样改写成vb中的代码做成dll文件来调用?求高手帮忙改写一下!<br/>vba代码如下:</p><p>Sub mc()<br/>Sheets(1).Unprotect Password:="123456"<br/>Sheets("xscj").Unprotect Password:="123456"<br/>cjzhs = Sheets(1)..CurrentRegion.Rows.Count '成绩表的总行数<br/>cjzls = Sheets(1)..CurrentRegion.Columns.Count - 1 '成绩表的总列数</p><p>Sheets("xscj").Select<br/>Cells.ClearContents</p><p>Sheets(1).Select<br/>Range(Cells(1, 1), Cells(cjzhs, cjzls)).Select<br/>Selection.Copy<br/>Sheets("xscj").Select<br/>Range("a1").Select<br/>Selection.PasteSpecial Paste:=xlPasteValues<br/>Application.CutCopyMode = False<br/>Worksheets("xscj").Range(Cells(2, 1), Cells(cjzhs, cjzls)).Sort Key1:=Worksheets("xscj").Range("a2"), Order1:=xlAscending, Key2:=Worksheets("xscj").Range("c2"), Order2:=xlAscending '以科类班级排序,使文科理科分开同一班的在一起<br/>kml = 7 'InputBox("请输入第一个学科所在的列号(数值):") * 1<br/>Cells(1, cjzls + 1) = "平均"<br/>Cells(1, cjzls + 2) = "总分"<br/>Cells(1, cjzls + 3) = "班名"<br/>Cells(1, cjzls + 4) = "年名"<br/>For i = 1 To cjzls - kml + 1<br/> Cells(1, cjzls + 4 + i) = Left(Cells(1, kml + i - 1), 1) & "名"<br/>Next i<br/>wlkb = Cells(2, 1)<br/>krs = WorksheetFunction.CountIf(Range(Cells(2, 1), Cells(cjzhs, 1)), wlkb) '取该科号的人数<br/>bjh = Cells(2, 3)<br/>kbh = 2<br/>brs = WorksheetFunction.CountIf(Range(Cells(2, 3), Cells(kbh + krs - 1, 3)), bjh) '取该班号的人数</p><p>bjhh = 2<br/>For i = 2 To cjzhs<br/> If WorksheetFunction.Sum(Range(Cells(i, kml), Cells(i, cjzls))) Then Cells(i, cjzls + 2) = WorksheetFunction.Sum(Range(Cells(i, kml), Cells(i, cjzls)))<br/> If Cells(i, cjzls + 2) > 0 Then Cells(i, cjzls + 1) = Round(WorksheetFunction.Average(Range(Cells(i, kml), Cells(i, cjzls))), 2)<br/>Next i<br/>For i = 2 To cjzhs<br/> If wlkb = Cells(i, 1) Then<br/> If bjh <> Cells(i, 3) Then<br/> bjhh = i<br/> bjh = Cells(i, 3)<br/> brs = WorksheetFunction.CountIf(Range(Cells(i, 3), Cells(kbh + krs - 1, 3)), bjh) '取该班号的人数<br/> End If<br/> Else<br/> kbh = i<br/> wlkb = Cells(i, 1)<br/> krs = WorksheetFunction.CountIf(Range(Cells(i, 1), Cells(cjzhs, 1)), wlkb) '取该科号的人数<br/> bjhh = i<br/> bjh = Cells(i, 3)<br/> brs = WorksheetFunction.CountIf(Range(Cells(i, 3), Cells(kbh + krs - 1, 3)), bjh) '取该班号的人数<br/> End If<br/> If Cells(i, cjzls + 2) > 0 Then<br/> Cells(i, cjzls + 3) = WorksheetFunction.Rank(Cells(i, cjzls + 2), Range(Cells(bjhh, cjzls + 2), Cells(bjhh + brs - 1, cjzls + 2)))<br/> Cells(i, cjzls + 4) = WorksheetFunction.Rank(Cells(i, cjzls + 2), Range(Cells(kbh, cjzls + 2), Cells(kbh + krs - 1, cjzls + 2)))<br/> End If<br/> For j = 1 To cjzls - kml + 1<br/> If WorksheetFunction.IsNumber(Cells(i, kml + j - 1)) Then Cells(i, cjzls + 4 + j) = WorksheetFunction.Rank(Cells(i, kml + j - 1), Range(Cells(kbh, kml + j - 1), Cells(kbh + krs - 1, kml + j - 1)))<br/> Next j<br/>Next i<br/>Sheets("xscj").Protect Password:="123456", AllowFormattingCells:=True, AllowFormattingColumns:=True, AllowFormattingRows:=True, AllowSorting:=True, UserInterfaceOnly:=True<br/>Sheets(1).Protect Password:="123456", AllowFormattingCells:=True, AllowFormattingColumns:=True, AllowFormattingRows:=True, UserInterfaceOnly:=True<br/>End Sub</p><p>先谢谢各位高手来帮我一下。<br/></p> 建议你直接用VB来调用Excel软件,这样Excel中就不存在任何代码了。VB做DLL非常难,这不是一句两句能说清(可能一千句也说不清)。 感谢<font face="Verdana" color="#61b713"><strong>黄玉宏</strong><font color="#29384e">高手指点,让我先学一学VB来调用Excel软件,不会的地方望能请教。</font></font>
页:
[1]