excel VBA - Userform cmd problem

Z

Zygoid

i have a user form that when the cmdbutton is clicked it opens anothe
workbook, inputs information in the next available space, then closes
without user seeing it open. The problem is when it closes, the "sav
as" window opens. is there coding i can use to automatically sav
changes and close the workbook without user seeing it close? here i
the code I have;

Private Sub CommandButtonOkay_Click()

Application.ScreenUpdating = False
Set SourceWB = Workbooks.Open("C:\greg\db.xls", _
False, True)


ActiveWorkbook.Sheets("Subdiv").Activate
Range("A1").Select
Do
If IsEmpty(ActiveCell) = False Then
ActiveCell.Offset(1, 0).Select
End If
Loop Until IsEmpty(ActiveCell) = True
ActiveCell.Value = txtSubdivision.Value
ActiveCell.Offset(0, 1) = cboCity.Value
ActiveCell.Offset(0, 2) = txtZip.Value
ActiveCell.Offset(0, 3) = txtDirections.Value

SourceWB.Close True

ActiveWorkbook.Sheets("Costing").Activate
Range("D5").Select

Unload Me

End Su
 
T

tolgag

Hi,

Try to save the workbook before closing and then close it withou
saving :

SourceWb.Save
SourceWB.Close False

P.S. : if the file's (opened) readonly, you'll get the Save As windo
again
 
C

chandlm

This line of code will close the workbook and save changes
automatically.

sourcewb.Close true
 
Z

Zygoid

I found out that the page was opening as "ready only"

so i changed the code from:
Set SourceWB = Workbooks.Open("C:\greg\db.xls", _
False, True)

to:
Set SourceWB = Workbooks.Open("C:\greg\db.xls")

and it works fine
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top