VBA到VB [英] VBA to VB

查看:82
本文介绍了VBA到VB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从未使用过VB,很抱歉新手提问。我在vba中有一个非常好的
小应用程序,只使用excel作为放置按钮的地方和一些我需要移动到VB的代码。现在看来soemone使用它并不是
可以访问excel。


在下面的代码中,应用程序在VB中导致一些问题。并且

游标xlwait也会导致一些问题。我想知道是否有人可以帮助我

将其转换为实际的VB应用程序。也许这是一个愚蠢的问题,但是我已经告诉我,如果我在Windows XP机器上编译它,它可能只会在一台XP机器而不是一台Windows上运行
2000机器。这是真的,如果

那么我可以做些什么来使它在两个操作系统上都能运行?


谢谢


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Sub Open_Write_File()

Dim sLineOfText As String

Dim sFile1 As String

Dim sFile2 As String

Dim iInt As Integer


''设置光标让用户知道我在工作。

''Application.Cursor = xlWait

''MsgBox"首先,让我们选择你要从中删除电话号码的文件,

vbOKOnly

sFile1 = Application.GetOpenFilename(" Text Files(* .txt),* .txt ;,

标题:=从删除电话号码中删除电话号码。)

MsgBox好了,现在让我们选择你要保存新文件的名称fils as,

vbOKOnly


sFile2 = Application.GetSaveAsFilename(" Text Files(* .txt),* .txt ",

标题:=&'创建没有电话号码的新文件)

打开sFile1输入为1

打开sFile2输出作为2


iInt = 0

Do EOF(1)


行输入#1,sLineOfText

sLineOfText =修剪(Mid(sLineOfText,1,729))

打印#2,sLineOfText

iInt = iInt + 1

循环

关闭#1,#2


''将光标恢复正常

Application.Cursor = xlDefault


MsgBox iInt& "记录更新没有电话号码,vbOKOnly


结束子

解决方案

一些事情:


这是一个讨论.NET开发环境的新闻组。

Excel VBA或VB 6.0都不是其中的一部分。


编写VB 6.0代码时,必须先引用Excel

对象库(从项目菜单中选择引用),然后才能编写

使用任何属于Excel世界的对象。


完成后,你需要制作一个"实例"的Excel

申请对象:


dim xl作为新的Excel.Application


然后你通过你的变量用于执行其他与Excel相关的任务。


还有很多要知道的,但是,这不是这个地方。


我会建议你试试:Microsoft.Public.Excel


" Striker" < st ********* @ qwest.netwrote in message

news:OA ************** @ TK2MSFTNGP03.phx.gbl。 ..


>我从未使用过VB,很抱歉新手提问。我在vba中有一个非常好的
小应用程序,只使用excel作为放置按钮的地方和一些我需要移动到VB的代码。现在看来soemone使用它并不是
可以访问excel。


在下面的代码中,应用程序在VB中导致一些问题。并且

游标xlwait也会导致一些问题。我想知道是否有人可以帮助我

将其转换为实际的VB应用程序。也许是一个愚蠢的问题,但是



有人告诉我,如果我在Windows XP机器上编译它,它可能只有
工作在XP机器而不是Windows 2000机器上。这是真的吗?

如果

那么我可以做些什么来使它在两个操作系统上都能运行?


谢谢


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $ b Sub Open_Write_File()

Dim sLineOfText As String

Dim sFile1 As String

Dim sFile2 As String

Dim IInt As Integer


''设置光标让用户知道我正在工作。

''Application.Cursor = xlWait


''MsgBox"首先让我们从你想要删除的电话号码中删除电话号码,

vbOKOnly

sFile1 = Application.GetOpenFilename(" ;文本文件(* .txt),* .txt",

标题:="从删除电话号码中删除电话号码。)

MsgBox"好的,现在让我们选择你想要保存新文件的文件名为,

vbOKOnly


sFile2 = Application.GetSaveAsFilename(" Text Files(* .txt),* .txt",

标题:="创建没有电话号码的新文件)


打开sFile1输入为1

打开sFile2输出为2


iInt = 0

Do EOF(1)


行输入#1,sLineOfText

sLineOfText =修剪(Mid(sLineOfText,1,729))

打印#2,sLineOfText

iInt = iInt + 1

循环

关闭#1,#2


''将光标恢复正常

Application.Cursor = xlDefault


MsgBox iInt& "记录更新没有电话号码,vbOKOnly


结束子



似乎因为我不小心在VB

部分发布了这个并且被告知要去Dot Net,所以有些混乱。我试图将VBA应用程序从

VBA移动到DOT Net,因为一个人无法访问VBA。


我希望这可以解决问题。

" Scott M." < s - *** @ nospam.nospamwrote in message

news:Oa ************** @ TK2MSFTNGP06.phx.gbl ...


>以下几点:


这是一个讨论.NET开发环境的新闻组。

Excel VBA或VB 6.0都不是其中的一部分。


编写VB 6.0代码时,必须引用Excel

对象库(从项目菜单中选择参考),然后才能使用任何属于Excel世界的对象。


完成后,你需要制作一个实例。的Excel

申请对象:


dim xl作为新的Excel.Application


然后你通过你的变量用于执行其他与Excel相关的任务。


还有很多要知道的,但是,这不是这个地方。


我会建议你试试:Microsoft.Public.Excel


" Striker" < st ********* @ qwest.netwrote in message

news:OA ************** @ TK2MSFTNGP03.phx.gbl。 ..


>>我从未使用过VB,很抱歉新手问题。我在vba中有一个非常小的应用程序,只使用excel作为放置按钮的地方和我需要移动到VB的一些代码。现在看来soemone使用它确实没有
可以访问excel。

在下面的代码中,应用程序在VB中导致一些问题。并且
游标xlwait也会导致一些问题。我想知道是否有人可以帮助我将其转换为实际的VB应用程序。也许是一个愚蠢的问题,
但是我已经被告知如果我在Windows XP机器上编译它,它可能只能在XP机器而不是Windows上工作2000机器。这是真的吗?
如果
那么我可以做些什么让它在两个操作系统上都能运行?

谢谢

~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~
Sub Open_Write_File()
Dim sLineOfText As String
Dim sFile1作为String
Dim sFile2 As String
Dim iInt As Integer

''设置光标让用户知道我正在工作。
''Application.Cursor = xlWait

''MsgBox"首先让我们选择你要从中删除电话号码的文件,
vbOKOnly
sFile1 = Application.GetOpenFilename(" Text Files(*。 txt),* .txt",
标题:="从删除电话号码中删除电话号码?)msgBox好了,现在让我们选择你想要保存新电影的文件名 ;,
vbOKOnly

sFile2 = Application.GetSaveAsFilename(" Text Files(* .txt),* .txt",
标题:="创建没有电话的新文件NUMBERS)

打开sF ile1输入为1
打开sFile2输出为2

iInt = 0
直到EOF(1)

线路输入#1,sLineOfText
sLineOfText =修剪(中(sLineOfText,1,729))
打印#2,sLineOfText
iInt = iInt + 1
循环
关闭#1,#2

''将光标恢复正常
Application.Cursor = xlDefault

MsgBox iInt& "记录更新没有电话号码,vbOKOnly

End Sub




你需要说清楚:你想要VBA到VB吗?或者VBA到VB.NET。

每个人(可能除了MS中的那些人,因为MS正式结束了支持

VB,所以对他们来说,只有一个叫VB的东西,就是VB.NET)把VB和VB.NET视为完全不同的东西。


如果你想做VBA到VB,你需要发布一个专用于

VB的NG(或称之为经典的VB)。


如果你想使用VB.NET (或者更常见,.NET,因为在.NET世界中,

哪种语言不重要,你可以选择C#,VB.NET,C ++来做

一样的以非常相似的方式)替换你的VBA代码,你有建立一个独立的应用程序来自动化你的Excel,建立一个

COM互操作dll您可以在Excel VBA中使用,或使用VSTO制作

您的代码可以更好地与Excel集成...


使用VB(经典VB)你有类似的选择,你可能会发现它有点

更容易转把你的代码从VBA推到VB,毕竟,他们是同一代的

技术。


不知道你打算做什么,看到你们中的更多人

代码,甚至你们正在尝试使用VB或VB.NET,很难说

这些东西真有帮助。

前锋 < st ********* @ qwest.netwrote in message

news:eQ ************** @ TK2MSFTNGP06.phx.gbl。 ..


因为我意外地在VB

部分发布了这个并且被告知要去Dot Net,这似乎有些混乱。我试图将VBA应用程序从

VBA移动到DOT Net,因为一个人无法访问VBA。


我希望这可以解决问题。


" Scott M." < s - *** @ nospam.nospamwrote in message

news:Oa ************** @ TK2MSFTNGP06.phx.gbl ...


>>以下几点:

这是一个讨论.NET开发环境的新闻组。
无论是Excel VBA还是VB 6.0是其中的一部分。

当您编写VB 6.0代码时,必须先引用Excel
对象库(从项目菜单中选择引用),然后才能
使用任何属于Excel世界的对象。

完成后,你需要制作一个实例。 Excel的应用程序对象:

dim xl作为新的Excel.Application

然后,您可以通过变量执行其他与Excel相关的任务。

还有很多要知道,但同样,这不是这个地方。

我建议你试试:Microsoft.Public.Excel


>"前锋" < st ********* @ qwest.netwrote in message
新闻:OA ************** @ TK2MSFTNGP03.phx.gbl ...


>>>我从未使用过VB,很抱歉新手提问。我在vba中有一个非常小的应用程序,只使用excel作为放置按钮的地方和我需要移动到VB的一些代码。现在看来soemone使用它确实没有
可以访问excel。

在下面的代码中,应用程序在VB中导致一些问题。并且
游标xlwait也会导致一些问题。我想知道是否有人可以帮助
我将它转换为实际的VB应用程序。也许是一个愚蠢的问题,
但是我已经被告知如果我在Windows XP机器上编译它,它可能只能在XP机器而不是Windows上工作2000机器。这是真的吗?
如果
那么我可以做些什么让它在两个操作系统上都能运行?

谢谢

~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~
Sub Open_Write_File()
Dim sLineOfText As String
Dim sFile1作为String
Dim sFile2 As String
Dim iInt As Integer

''设置光标让用户知道我正在工作。
''Application.Cursor = xlWait

''MsgBox"首先让我们选择要删除电话号码的文件
来自,
vbOKOnly
sFile1 = Application.GetOpenFilename(" Text文件(* .txt),* .txt",
标题:="从删除电话号码中删除电话号码?)msgBox好了,现在让我们选择你要保存的文件名新的fils为,
vbOKOnly

sFile2 = Application.GetSaveAsFilename(" Text Files(* .txt),* .txt",
Title:=" CREATE没有电话号码的新文件")

Op en sFile1输入为1
打开sFile2输出为2

iInt = 0
直到EOF(1)

线路输入#1, sLineOfText
sLineOfText = Trim(Mid(sLineOfText,1,729))
打印#2,sLineOfText
iInt = iInt + 1
循环
关闭#1,# 2

''将光标恢复正常
Application.Cursor = xlDefault

MsgBox iInt& "记录更新没有电话号码,vbOKOnly

End Sub





I have never used VB, so sorry for the novice questions. I have a very
small app in vba that only uses excel as a place to put a button and some
code that I need to move to VB. Now it seems soemone who uses it does not
have access to excel.

In the following code the application causes some problems in VB. and the
cursor xlwait also causes some problems. I wonder if someone can help me
convert this to a actual VB application. Also maybe a silly question, but I
have been told that if I compile this on a Windows XP machine, it may only
work on an XP machine and not a windows 2000 machine. Is this true, and if
so is there anything I can do to make it work on both operating systems?

Thank You

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~

Sub Open_Write_File()
Dim sLineOfText As String
Dim sFile1 As String
Dim sFile2 As String
Dim iInt As Integer

''set cursor to let user know I''m working.
''Application.Cursor = xlWait
''MsgBox "First lets pick the file you want to remove phone numbers from",
vbOKOnly
sFile1 = Application.GetOpenFilename("Text Files (*.txt), *.txt",
Title:="PICK THE FILE TO REMOVE PHONE NUMBERS FROM")
MsgBox "OK, now lets pick a file name you want to save the new fils as",
vbOKOnly

sFile2 = Application.GetSaveAsFilename("Text Files (*.txt), *.txt",
Title:="CREATE NEW FILE WITHOUT TELEPHONE NUMBERS")
Open sFile1 For Input As 1
Open sFile2 For Output As 2

iInt = 0
Do Until EOF(1)

Line Input #1, sLineOfText
sLineOfText = Trim(Mid(sLineOfText, 1, 729))
Print #2, sLineOfText
iInt = iInt + 1
Loop
Close #1, #2

''return cursor to normal
Application.Cursor = xlDefault

MsgBox iInt & " records updated without phone numbers", vbOKOnly

End Sub


解决方案

A couple of things:

This is a newsgroup that discusses the .NET development environment.
Neither Excel VBA or VB 6.0 are part of that.

When you write your VB 6.0 code, you must make a reference to the Excel
Object Library (from the Project menu, choose References), before you can
use any object that is part of Excel''s "world".

After you have done that, you''ll need to make an "instance" of the Excel
Application object:

dim xl As New Excel.Application

You then go through your variable to do other Excel related tasks.

There is much more to know, but again, this is not the place.

I would suggest you try: Microsoft.Public.Excel


"Striker" <st*********@qwest.netwrote in message
news:OA**************@TK2MSFTNGP03.phx.gbl...

>I have never used VB, so sorry for the novice questions. I have a very
small app in vba that only uses excel as a place to put a button and some
code that I need to move to VB. Now it seems soemone who uses it does not
have access to excel.

In the following code the application causes some problems in VB. and the
cursor xlwait also causes some problems. I wonder if someone can help me
convert this to a actual VB application. Also maybe a silly question, but
I
have been told that if I compile this on a Windows XP machine, it may only
work on an XP machine and not a windows 2000 machine. Is this true, and
if
so is there anything I can do to make it work on both operating systems?

Thank You

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~

Sub Open_Write_File()
Dim sLineOfText As String
Dim sFile1 As String
Dim sFile2 As String
Dim iInt As Integer

''set cursor to let user know I''m working.
''Application.Cursor = xlWait
''MsgBox "First lets pick the file you want to remove phone numbers from",
vbOKOnly
sFile1 = Application.GetOpenFilename("Text Files (*.txt), *.txt",
Title:="PICK THE FILE TO REMOVE PHONE NUMBERS FROM")
MsgBox "OK, now lets pick a file name you want to save the new fils as",
vbOKOnly

sFile2 = Application.GetSaveAsFilename("Text Files (*.txt), *.txt",
Title:="CREATE NEW FILE WITHOUT TELEPHONE NUMBERS")
Open sFile1 For Input As 1
Open sFile2 For Output As 2

iInt = 0
Do Until EOF(1)

Line Input #1, sLineOfText
sLineOfText = Trim(Mid(sLineOfText, 1, 729))
Print #2, sLineOfText
iInt = iInt + 1
Loop
Close #1, #2

''return cursor to normal
Application.Cursor = xlDefault

MsgBox iInt & " records updated without phone numbers", vbOKOnly

End Sub



Seems to be some confusion since I accidentally posted this in the VB
section and was told to go to Dot Net. I am trying to move a VBA app from
VBA to DOT Net as one person does not have access to VBA.

I hope this clears up things.
"Scott M." <s-***@nospam.nospamwrote in message
news:Oa**************@TK2MSFTNGP06.phx.gbl...

>A couple of things:

This is a newsgroup that discusses the .NET development environment.
Neither Excel VBA or VB 6.0 are part of that.

When you write your VB 6.0 code, you must make a reference to the Excel
Object Library (from the Project menu, choose References), before you can
use any object that is part of Excel''s "world".

After you have done that, you''ll need to make an "instance" of the Excel
Application object:

dim xl As New Excel.Application

You then go through your variable to do other Excel related tasks.

There is much more to know, but again, this is not the place.

I would suggest you try: Microsoft.Public.Excel


"Striker" <st*********@qwest.netwrote in message
news:OA**************@TK2MSFTNGP03.phx.gbl...

>>I have never used VB, so sorry for the novice questions. I have a very
small app in vba that only uses excel as a place to put a button and some
code that I need to move to VB. Now it seems soemone who uses it does
not
have access to excel.

In the following code the application causes some problems in VB. and
the
cursor xlwait also causes some problems. I wonder if someone can help me
convert this to a actual VB application. Also maybe a silly question,
but I
have been told that if I compile this on a Windows XP machine, it may
only
work on an XP machine and not a windows 2000 machine. Is this true, and
if
so is there anything I can do to make it work on both operating systems?

Thank You

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~

Sub Open_Write_File()
Dim sLineOfText As String
Dim sFile1 As String
Dim sFile2 As String
Dim iInt As Integer

''set cursor to let user know I''m working.
''Application.Cursor = xlWait
''MsgBox "First lets pick the file you want to remove phone numbers from",
vbOKOnly
sFile1 = Application.GetOpenFilename("Text Files (*.txt), *.txt",
Title:="PICK THE FILE TO REMOVE PHONE NUMBERS FROM")
MsgBox "OK, now lets pick a file name you want to save the new fils as",
vbOKOnly

sFile2 = Application.GetSaveAsFilename("Text Files (*.txt), *.txt",
Title:="CREATE NEW FILE WITHOUT TELEPHONE NUMBERS")
Open sFile1 For Input As 1
Open sFile2 For Output As 2

iInt = 0
Do Until EOF(1)

Line Input #1, sLineOfText
sLineOfText = Trim(Mid(sLineOfText, 1, 729))
Print #2, sLineOfText
iInt = iInt + 1
Loop
Close #1, #2

''return cursor to normal
Application.Cursor = xlDefault

MsgBox iInt & " records updated without phone numbers", vbOKOnly

End Sub




You need to make it clear: Do you want to "VBA to VB" or "VBA to VB.NET".
Everyone (maybe except for those in MS, since MS officially ended support to
VB, so for them, there is only one thing called VB, that is, VB.NET) regard
VB and VB.NET as totally different things.

If you want to do VBA to VB, you need to post to one of the NGs dedicated to
VB (or call it classical VB).

If you want to use VB.NET ( or mor egeneral, .NET, since in .NET world,
which language is not important, you can choose C#, VB.NET, C++ to do the
same thing in the very similar way) to replace your VBA code, you have
coices of building a stand-alone app to automation your Excel, building a
COM interop dll that you can use inside Excel VBA, or using VSTO to make
your code have better integration with Excel...

With VB (classical VB) you have similar choices and you may find it is a bit
easier to transfer your code from VBA to VB, after all, they are the
technologyies of the same generation.

Without knowning what exactly you are intending to do and see more of you
code, and even you are trying on VB or VB.NET, it is difficult to say
something really helpful.
"Striker" <st*********@qwest.netwrote in message
news:eQ**************@TK2MSFTNGP06.phx.gbl...

Seems to be some confusion since I accidentally posted this in the VB
section and was told to go to Dot Net. I am trying to move a VBA app from
VBA to DOT Net as one person does not have access to VBA.

I hope this clears up things.
"Scott M." <s-***@nospam.nospamwrote in message
news:Oa**************@TK2MSFTNGP06.phx.gbl...

>>A couple of things:

This is a newsgroup that discusses the .NET development environment.
Neither Excel VBA or VB 6.0 are part of that.

When you write your VB 6.0 code, you must make a reference to the Excel
Object Library (from the Project menu, choose References), before you can
use any object that is part of Excel''s "world".

After you have done that, you''ll need to make an "instance" of the Excel
Application object:

dim xl As New Excel.Application

You then go through your variable to do other Excel related tasks.

There is much more to know, but again, this is not the place.

I would suggest you try: Microsoft.Public.Excel


"Striker" <st*********@qwest.netwrote in message
news:OA**************@TK2MSFTNGP03.phx.gbl...

>>>I have never used VB, so sorry for the novice questions. I have a very
small app in vba that only uses excel as a place to put a button and
some
code that I need to move to VB. Now it seems soemone who uses it does
not
have access to excel.

In the following code the application causes some problems in VB. and
the
cursor xlwait also causes some problems. I wonder if someone can help
me
convert this to a actual VB application. Also maybe a silly question,
but I
have been told that if I compile this on a Windows XP machine, it may
only
work on an XP machine and not a windows 2000 machine. Is this true, and
if
so is there anything I can do to make it work on both operating systems?

Thank You

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Sub Open_Write_File()
Dim sLineOfText As String
Dim sFile1 As String
Dim sFile2 As String
Dim iInt As Integer

''set cursor to let user know I''m working.
''Application.Cursor = xlWait
''MsgBox "First lets pick the file you want to remove phone numbers
from",
vbOKOnly
sFile1 = Application.GetOpenFilename("Text Files (*.txt), *.txt",
Title:="PICK THE FILE TO REMOVE PHONE NUMBERS FROM")
MsgBox "OK, now lets pick a file name you want to save the new fils as",
vbOKOnly

sFile2 = Application.GetSaveAsFilename("Text Files (*.txt), *.txt",
Title:="CREATE NEW FILE WITHOUT TELEPHONE NUMBERS")
Open sFile1 For Input As 1
Open sFile2 For Output As 2

iInt = 0
Do Until EOF(1)

Line Input #1, sLineOfText
sLineOfText = Trim(Mid(sLineOfText, 1, 729))
Print #2, sLineOfText
iInt = iInt + 1
Loop
Close #1, #2

''return cursor to normal
Application.Cursor = xlDefault

MsgBox iInt & " records updated without phone numbers", vbOKOnly

End Sub





这篇关于VBA到VB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆