Jump to content
The mkiv Supra Owners Club

Any Visual Basic Guru's?


monsween

Recommended Posts

Alright chaps. Anyone handy with Visual basic for excel?

 

 

I would like to be able to reference cells so that certain information can be put into an email that can then be used to inform the correct person what stock to order.

 

Here is what i've come up with so far:

 

Sub OrderStock()

'Variable declaration

Dim oApp As Object, _

oMail As Object, _

WB As Workbook, _

FileName As String

 

'Turn off screen updating

Application.ScreenUpdating = False

 

'Create the email template

Dim strbody As String

With ActiveSheet

strbody = "Hi," & vbNewLine & vbNewLine & _

"Could you order these items for me" & vbNewLine & vbNewLine & _

"Part Number: " & _

.Range("A34") & vbNewLine & _

"Description: " & _

.Range("B34") & vbNewLine & _

"Quantity: " & _

.Range("N34") & vbNewLine & vbNewLine & vbNewLine & _

"Regards" & vbNewLine & _

"Stores"

End With

 

 

'Create and show the outlook mail item

Set oApp = CreateObject("Outlook.Application")

Set oMail = oApp.CreateItem(0)

With oMail

'Uncomment the line below to hard code a recipient

.To = "[email protected]"

'Uncomment the line below to hard code a subject

.Subject = "Order"

.Body = strbody

.Display

 

End With

 

 

 

End Sub

 

The problem being is that i want one marco that can be used for the whole operation.

 

The values i need are from the collumns A,B and N. and rows 10-200+

 

How do i change it so i can reference one specific set of A's B's and N's?? IE in the example above it references row 34 into the email.

 

I have a button that is linked to the macro then a box next to it to type in the row number that is to be ordered.

 

So if item in row 54 needed to be ordered, type 54 into the box then hit the order button and the correct data would be referenced from A54, B54 and N54. Then subsequently sent out via email.

 

 

Thanks in advance

Kieran

Link to comment
Share on other sites

You can use the following to get the text from a CELL.

 

Cells(1, 1).Text

 

So you could use

.Range("A&Cells(x, y).Text) & vbNewLine & _

 

Where x = row number and y = column number.

 

Even better DIM a variable up the top MyRowNumber

Set this to the value and then put that into the line above.

 

.Range("A&MyRowNumber) & vbNewLine & _

 

 

See if that works..

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. You might also be interested in our Guidelines, Privacy Policy and Terms of Use.