Send Ascii command in vba - vba

I am fairly new to vba. Appologies if this is a simple question, but after 3 days on google im starting to feel dumb.
I am writing a very simple POS program to take stock in a bar. Part of the program is a Till point function. I am writing in excel VBA. I have a generic pos printer connected to a generic cash drawer. Printer is connected via usb to pc.
My question: i am unable to get the cash drawer to kick open when a receipt is printed. It is printing the reciepts fine, but i do not how how to send a ascii - esc/pos command to the printer.
I know that i should use "chr(27), chr(112)" , but how?!
As a last resort Ive tried pasting those chars in a cell and used cells("A1").printout function but that just sends it to the printer as text to be printed and not a command.
Any help would be greatly appreciated.
Marchant

This link suggests:
Option Explicit
Sub testme01()
Open "LPT1:" For Output As #1
Print #1, chr(27)+chr(112)
Close #1
End Sub

Related

How to trace an output in Access back to the section of VBA code that produced it

I am working on updating an Access database with this year's new data. I did not write the code that goes along with it, and am trying to find out where the formula is for an output (ratios) that the VBA code produces. Is there a way to trace back where the output came from?
I've tried just doing CTRL F to find the word "ratio" in the code but it's so long I can't pin down exactly where it's coming from.
No error messages
In debug mode you can step through the code step by step by pressing F8. You should be able to find the origin of every data export that way.
If the outputed data is a result of calculations I would check every query in the database. One of these probably takes care of those ratio's.

Excel VBA to read Code 128 barcode

I am trying to create a VBA code to read input from a barcode scanner. Specifically I'm interested in reading code 128 barcodes. I read on a different post that the barcode scanner is basically a "keyboard" that types the input when scanning to the application. I don't whether this can be replicated in Excel using VBA. Any ideas will be appreciated.
I am looking for something like this:
Sub BarcodeScannerReader()
Dim sMyCode As String
sMyCode=input("Scan Code:")
Range("A1"). Value=sMyCode
End Sub
You need the barcode fonts installed, and your barcode reader set up to write to the cell you're interested in. The scanner really does work like a keyboard - it will read the code and 'type' the results wherever you direct it to. This isn't something you do in VBA (unless I'm misunderstanding your question).

Getting a Screenshot From A Bloomberg Terminal

I have a project and it requires grabbing multiple screenshots from a Bloomberg Terminal and I'd like to automate it.
This what I have so far:
Dim abc As Variant
Dim CUSIP As String
CUSIP = Range("A1")
ch = DDEInitiate("winblp", "bbk")
Call DDEExecute(abc, "<blp-1>" & CUSIP & " mtge<GO>")
Call DDEExecute(abc, "<blp-1> CFG<Go>")
Call DDEExecute (abc, "blp-1 <copy>")
Call DDETerminate(ch)
This correctly gets me to the graph I want (in this case the CFG, or Cash Flow Graph), but from this point, I am unable to figure out a screenshot method. In Bloomberg, there are a few commands, but they all require the use of a mouse. I've seen some do it before where they are able to get the requisite screenshots, but I can't figure out how.
So basically, I can use excel and VBA to get Bloomberg to pull up the correct screen, but now I just need to figure out a way to grab snipshot for the thing.
It's worth mentioning that the copy line just copies the data, not an image (which is what I was hoping for).
One option is to send the screenshot to your personal email address and download it from there:
Run GRAB in blp-1
Enter your personal email address
Download it manually from there or use an IMAP library to do so automatically
Another option is to use a 3rd party grabbing utility that has command line options. For example, Snagit can be started with an argument that creates a screenshot: http://informationworker.ru/snagit10.en/snagit_4_technical_reference.4.35.html

Systematically Hyperlinking text in Word VBA

I work for a company that does custom reports in Microsoft Word very frequently. I would like to write a VBA Macro that systematically goes through the following list and Hyperlinks ONLY the text (not paragraph symbols or tab arrows or list number) and links to a bookmark in the current document.
1 → Description of Figure 1 ¶
¶
2 → Description of Figure 2 ¶
¶
3 → Description of Figure 3 ¶
¶
4 → Description of Figure 5 ¶
¶
After the macro is complete, clicking on "Description of Figure 1" will go to bookmark Figure_01 which exists later in the same document. I appreciate any help that anyone can give!
We can't just go ahead and write it for you, that is not the nature of the site, however, I don't want to tell you to go off and come back with some more effort and we'll support that.
I want to provide some pointers for you to get you going. Once you have got so far but are getting stuck on specific issues (e.g. 'why do I get error X' or 'why is my loop not capturing everything'), that's the time this site will shine for you and give great support!
So where to start? I'm going to assume non VBA experience and the below a crash course.
First we need a procedure that we can run. In Word press Alt+F11, this opens the VBE (VBA-Editor)
From the project window on the top left side (usually) double click on 'ThisDocument' and the main window will become a space for us to write code. The first first thing to write at the very top is Option Explicit, this is telling the VBA runtime that all variables must be declared, which is good practice.
Next below that enter: -
Public Sub CreateLinks()
End Sub
You have now created a procedure called CreateLinks, while your insertion point (vertical blinking line) is between these two lines of code you can push F8 to step through code line by line, or F5 to run it all in one go.
That's the start of everything. Now what you need to do is.
Connect to the document
Find the text to link to
Find the text to link from
Create link
Repeat steps 2 - 5 until all links are done.
That should bring you to your answer.
As further pointers/hints to help you: -
The Application holds a collection of documents, you could look through them or open your document to connect to it
a Document has a collection of bookmarks and hyperlinks, you can loop through these while getting to your goal
Selection is that active selected text
I hope this is of help.

Print to POS Display Unit

I have an Epson Display Unit (for the Point of Sale), and have it set up as a printer. I can only get it to print what I want when I go to Printer Properties > Fonts (there is a test input box).
However printing from an app such as notepad yields no results. I'm trying to get it to work with the p.o.s. app I made in Excel. I found a COMM port communication script here, but I can't get past the OPEN command. Seems there's a "file in use". I'd like to know if anyone else has had experience with this sort of thing.
Under the assumption that your printer is connected to serial interface 1, provided that the serial interface parameters are correctly set, and you want to send a string of characters to that interface, you may try this ...
Sub WriteToCOM()
Open "COM1:" For Output As #1
Write #1, "ddd"
Close #1
End Sub
Paste this code into an Excel VBA script and cycle thru it with F8 - it worked for me
You may replace "COM1:" by any existing "COMx:" or "LPTx:" as well (don't forget the semicolon!)
I am using this to control an Amateur Radio (setting the frequency) from an Excel table containing broadcast station names and their frequencies. I am of course sending special characters to my gear using the chr() function.
The Macro is tied to a control button. My Excel is Office 2003 (it worked already in Office97)
Good luck
MikeD