Solved

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

Posted on 2011-09-17
7
148 Views
Last Modified: 2012-05-12
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
Comment
Question by:TimJar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 33

Expert Comment

by:Norie
ID: 36554869
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
 

Author Comment

by:TimJar
ID: 36554913
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
 
LVL 33

Expert Comment

by:Norie
ID: 36554949
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!

 

Author Comment

by:TimJar
ID: 36554964
I don't know much about automating IE. Can you tell me what I should be researching?
0
 
LVL 33

Expert Comment

by:Norie
ID: 36554973
I don't know where you would research it.

If you can post the URL I could probably post some code.
0
 

Author Comment

by:TimJar
ID: 36555009
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
 
LVL 33

Accepted Solution

by:
Norie earned 500 total points
ID: 36555050
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question