ANSWERED! Transfer file through COM/RS232/SERIAL/PORT

McLaren

Board Regular
Joined
Jul 12, 2003
Messages
122
Time for McLaren to finally give something back to the community. Figured I'd post it here in case someone does a search. I spent probably the past week trying to figure out how to send a file through COM1 to a CNC machine and didn't have any luck until today. It took a lot of searching and trying out other's code, but this worked for me.

1. Get MSCOMM32.OCX if you don't have it. I got it here:
http://www.martin2k.co.uk/vb6/ocxs/mscomm32.zip

2. Put it in C:\Windows\System32

3. Go to (START)(RUN) type without quotes "regsvr32.exe C:\Windows\system32\mscomm32.ocx"

5. Open Excel

6. (TOOLS)(MACRO)(VISUAL BASIC EDITOR)

7. (INSERT)(USERFORM)

8. (VIEW)(TOOLBOX)

9. RightClick Toolbox, select (ADDITIONAL CONTROLS)

10. Scroll down to "Microsoft Communications Control, version 6.0"

11. Check the box and hit (OK)

12. There should now be a icon of a telephone on the Toolbox. Drag it onto your userform

13. Set the Properties of it however you need.

14. (VIEW)(CODE)

15. My code is written so that when CommandButton2 is clicked the file is sent. I'm not entirely sure how much of this you need, but this is what worked for me. I have a Excel sheet that gets updated with the information I need, then it gets pasted into a word file, saved onto the desktop, then posted out of the COM1 port. I have no idea what "& Chr(13)" is doing(actually don't understand most of the sending code), but without it I didn't have line breaks in the output. The relevant transmitting code is in between the spaces

Code:
Private Sub CommandButton2_Click()
Dim appWD As Word.Application
Set appWD = CreateObject("Word.Application.8")
appWD.Visible = False
Sheets("Calculator").Select
Sheets("Template").Range("A10").Value = Range("J2").Value
Sheets("Template").Select
Range("A1:A42").Copy
appWD.Documents.Add
appWD.Selection.Paste
appWD.ActiveDocument.SaveAs FileName:="C:\Documents and Settings\All Users\Desktop\temp.tap", FileFormat:=wdFormatText
appWD.ActiveDocument.Close
appWD.Quit

If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True
FreeNum = FreeFile
Open "C:\Documents and Settings\All Users\Desktop\temp.tap" For Input As #FreeNum
Do While Not EOF(FreeNum)
Line Input #FreeNum, TextLine
MSComm1.Output = TextLine & Chr(13)
Loop
Close #FreeNum
MSComm1.PortOpen = False
End If

Sheets("Calculator").Select
End Sub


Well, I think that about covers it. Enjoy!
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Thanks for the info ! I have seen the question asked numeros times with no reply.
 
Upvote 0
I did all the steps from 1 to 11 without any problem
but on step 12 I have this error msg:
The control could not be created because it is not properly licenesed

Excel 2000, windows 98

thanks
 
Upvote 0
I have no idea. Did you use the link I gave, or did you already have mscomm32.ocx?

Hopefully someone smarter than myself will have an idea.
 
Upvote 0
in 2 computers, I used your link. in the third one - with excel 2002 and windows XP, it was already there
but the msg was the same:
The control could not be created because it is not properly licenesed

is it possible, that it was so because i tested it in computers without the communication?
 
Upvote 0
Maybe try unregistering it, then reregistering, that's about all I found on google.
regsvr32.exe /u C:\Windows\system32\mscomm32.ocx
regsvr32.exe C:\Windows\system32\mscomm32.ocx
 
Upvote 0
Hi McLaren, hi all.
JUST IF YOU ARE STILL THERE...
The "& Chr(13)" adds a carriage return in a string variable.
13 is the number of the ASCII contro code for the CR.
The error of
I'm trying to do something like you; but in my case itisn't a CNC. It is a serial port label printer INTERMEC 3400, which needs to get a file with all the commands to print text, lines, bar codes etc. So I take the values of weight, etc from a spreadsheet, make a file.txt and... I'm trying to send it via COM1 to the printer.
Well, thank you for your post.
Finis
 
Upvote 0

Forum statistics

Threads
1,215,332
Messages
6,124,314
Members
449,153
Latest member
JazzSingerNL

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top