• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 157
  • Last Modified:

Using a macro to copy a cell to a field on a web page

Hello,

I would  like to create a macro to copy data from a group of cells to a group of fields on a web page. My company has a web site that we can go to, create a new flyer, input about 15 data fields and then print the flyer to hand out. I have a spread sheet that calculates the data for me. Now I want to copy the data one cell at a time and past it to the web site one field at a time. I created a macro by recording key strokes (ctrl+c alt+tab ctrl+v tab ctrl+c etc...) just the way I would do it manually but it doesn't work. It won't switch over to the web page that I have open. Is there a way to do this?
Thanks,
Tim
0
TimJar
Asked:
TimJar
  • 4
  • 3
1 Solution
 
NorieCommented:
Tim

One way you can do this by automating IE.

It should be quite straightforward, something like this.

1 Navigate to page.

2 Grab references to the data fields on the page.

3 Put the values from Excel into the data fields

4 Submit the page if required.

The individual steps would need to be refined of course but that's the basics.
0
 
TimJarAuthor Commented:
How would you do step 2. I can do it manually like this:

1. Select the first field in the page
2. alt+tab to go to the .xls file
3. select the first cell
4. ctrl+c
5. al+tab to go back
6. ctrl+v
7. tab to next field
and so on
0
 
NorieCommented:
It's hard to be specific as it really depends on the page and how it's designed.

It also depends on the data in Excel.

With the approach I'm suggesting there wouldn't be any tabbing/selecting.


0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
TimJarAuthor Commented:
I don't know much about automating IE. Can you tell me what I should be researching?
0
 
NorieCommented:
I don't know where you would research it.

If you can post the URL I could probably post some code.
0
 
TimJarAuthor Commented:
I think you have to be on our VPN to access it but here is the URL

http://www.cgxsolutions.com/idesign/index.asp
0
 
NorieCommented:
This is how you could do the login using VBA, it takes the username and password from a worksheet.
Option Explicit

Sub LogIn()
Dim IE As Object
Dim doc As Object
Dim frm As Object
Dim inpUser As Object
Dim inpPword As Object
Dim strURL As String

    strURL = "http://www.cgxsolutions.com/idesign/index.asp"

    Set IE = CreateObject("InternetExplorer.Application")

    With IE

        .navigate strURL

        Do While .Busy: DoEvents: Loop
        Do While .ReadyState <> 4: DoEvents: Loop
        .Visible = True

        Set doc = .document



        With doc

            Set frm = .forms(0)

            Set inpUser = .getelementbyid("frmUser") ' get reference to input for username

            inpUser.Value = Range("B1").Value ' put value from B1 into username

            Set inpPword = .getelementbyid("frmPWord") ' get reference to password input

            inpPword.Value = Range("B2").Value ' use value in B2 for password

        End With

        frm.submit ' now submit the login form

       ' .Quit ' Optional
    End With

End Sub

Open in new window

If you look at the source code of the page you want to fill out you will find the names/ids for the data fields.

Then you can use the same method this code uses to put values from the worksheet in the fields on the page.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now