如何在EXCEL中运行此宏文件?

iwfkc 2008-01-22 06:39:15
Sub pipeindex()
Open "d:\PIPEINDEX.TXT" For Input As #1
Line Input #1, s
Line Input #1, s
While Not EOF(1)
Line Input #1, s
If Trim(s) <> "" Then
a = Left(s, 50)
b = Right(s, 50)
a = Trim(a)
b = Trim(b)
c = Len(a) - 1
a = Right(a, c)

Selection.TypeText Text:=a
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:=b
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell

End If
Wend
Close #1
End Sub

此代码能在WORD中运行,可在EXCEL中Selection.TypeText Text:=a这句总出错
如何修改才能在EXCEL中运行呀?
...全文
129 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
黑领 2008-02-25
  • 打赏
  • 举报
回复
也一样,
Range("A" & i).Select     改为
Range(char(65) & i).select 'char(65)代表A,同理char(66)代表B,依次类推
iwfkc 2008-01-24
  • 打赏
  • 举报
回复
谢谢!!如何在列之间自动输入呀?从A到AZ
黑领 2008-01-23
  • 打赏
  • 举报
回复
上面的那些东西有些都是WD里特有的参数,你可以这样:
要EXCEL里,不是用selection而是CELL
要在B5单元格输入123可以这样:
Range("B5").Select
ActiveCell.FormulaR1C1 = "123"
我认为可以这样改:
dim i as integer
i=1
Sub pipeindex()
Open "d:\PIPEINDEX.TXT" For Input As #1
Line Input #1, s
Line Input #1, s
While Not EOF(1)
Line Input #1, s
If Trim(s) <> "" Then
a=Left(s, 50)
b=Right(s, 50)
a=Trim(a)
b=Trim(b)
c=Len(a)-1
a=Right(a,c)

Range("A" & i).Select     ‘第一次运行时是A1
ActiveCell.FormulaR1C1 = a
Range("A" & i+2).Select     ’然后是A3
i=i+2 '下次是A5
End If
Wend
Close #1
End Sub

声明啊,我可没试过!应该差不多!你试试!


7,785

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧