Results 1 to 8 of 8

Thread: form freezing up

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2006
    Posts
    27

    form freezing up

    I last touched this code a few months ago, and for some reason it no longer works. When I push a 'commandbutton' in Word it is suppose to extract data from Excel and insert it into Word. However now when i press the 'commandbutton' it appears it just freezes and no data is pressed. both files are in the correct place on my computer to call up.

    VB Code:
    1. Public Sub CommandButton1_Click()
    2. HideListBoxes
    3.  
    4. Dim oDoc As Word.Document
    5.  
    6. Set oDoc = Application.Documents("C:\wordfile.doc")
    7. Dim oExcel As Excel.Application, myWB As Excel.Workbook
    8.    
    9. Set oExcel = New Excel.Application
    10. Set myWB = oExcel.Workbooks.Open("C:\excelfile.xls")
    11.  
    12. Dim b As Integer
    13.  
    14. b = CInt(myWB.Sheets("Sheet1").Range("B20").Value)
    15.  
    16. For i = 20 To b
    17.     oDoc.Bookmarks("bookmark1").Range.Text = myWB.Sheets("Sheet1").Cells(i, 2)
    18.    
    19. Next i
    20.  
    21. Set myWB = Nothing
    22. End Sub

    VB Code:
    1. Private Sub HideListBoxes()
    2.  
    3. CommandButton1.Visible = False
    4. End Sub
    Last edited by Pegasus0990; Jan 19th, 2007 at 10:34 AM.

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Nov 2006
    Posts
    27

    Re: form freezing up

    a little more detail.

    when i use to push the 'command button' all the data i was trying to get from excel was passed to word. however now, when the 'command button' is pushed, it just accepts getting pushed, then freezes.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Nov 2006
    Posts
    27

    using a different computer

    i have the following referenced.

    VB for apps
    word 11.0 object library
    excel 11.0 object library
    office 11.0 object library
    forms 2.0 object library
    ole automation
    normal

    when i last worked on this code, i was using a different computer, so wondering if this could be the problem.
    Last edited by Pegasus0990; Jan 18th, 2007 at 06:44 PM.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Nov 2006
    Posts
    27

    Re: form freezing up

    removing all reference to "hidelistboxes" doesnt work. when the commandbutton is pushed. the form still causes the program to freeze.

    i swear, that 2 months ago, this same exact code worked.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Nov 2006
    Posts
    27

    Re: form freezing up

    the value of "B20" in this instance is the integer 18


    could i maybe just not have something reference?

  6. #6
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: form freezing up

    VB Code:
    1. b = CInt(myWB.Sheets("Sheet1").Range("B20").Value)
    2.  
    3. For i = 20 To b

    if Range("B20").Value =18 then
    your For loop will be 20 to 18?

    is that what you want?

    change the value of Range("B20").Value = 25 and then check
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Nov 2006
    Posts
    27

    Re: form freezing up

    not exactly, the value of "B20" will be determined from VB located inside of Excel. The Excel VB is working fine.

    when i do a watch inside the Word VB (the code I provided), the value of "B20" is indeed 18, like i intended. the issue is that accept i press my command button, the code never completes itself, hence freezes.

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Nov 2006
    Posts
    27

    Re: form freezing up

    //here is the code for my Excel file//and attached is the code for my Word File//I deleted all non relevant data//the Word file contains a bookmark//enable 'view bookmark' to see it//when the Word Macro is ran, it is suppose to grab the infomation which in this case is "Test1" and "Test2" and insert it into the "bookmark1" location//in the file "wordfromexcel" is what my Excel doc looks like, "Test1" is in both the location "A18" and "D12," and "Test2" is in both "A19" and "D9." Basically, when a value of the C column="no" then the data is sent to the A column, where Word will extract it via bookmarks.

    //excel VB
    VB Code:
    1. Sub proc1()
    2.  
    3.  Dim j As Integer
    4.  Dim k As Integer
    5.  k = 20
    6.  For j = 9 To 14
    7.  
    8.     If Worksheets("Questions").Cells(j, 3) = "No" Then
    9.         k = k - 1
    10.         Worksheets("Questions").Cells(k, 1) = Worksheets("Questions").Cells(j, 4)
    11.     End If
    12.  Next j
    13.  
    14. Range("B20").Value = k
    15.  
    16. End Sub
    Attached Files Attached Files
    Last edited by Pegasus0990; Jan 19th, 2007 at 10:35 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width