View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
John John is offline
external usenet poster
 
Posts: 2,069
Default save user inputs from userform in a seperate workbook

Hi Sam,

you set your workbook reference incorrectly. Try this:

Dim DBFile As String
Dim MyPassword As String
Dim iRow As Long
Dim ws As Worksheet

MyPassword = "new"

DBFile = "H:\myfiles\Demo.xlsm"
Set DestWB = Workbooks.Open(DBFile, Password:=MyPassword)

Set ws = DestWB.Worksheets("Sheet1")

'find first empty row in database

With ws
iRow = .Cells(.Rows.Count, 1).End(xlUp).Offset(1, 0).Row

'do all your stuff here that refers to the shared workbook

End With



DestWB.Close True

You will note that within the with statement I placed a period . (full stop)
infront of Rows - this is to fully qualify to worksheet - not a problem in
2003 but understand it may cause problems in 2007

Hope works ok for you.

--
jb


"sam" wrote:

Hey John, Can you help me a little more with your code.. I tried using your
code but I am getting an error msg:

Run-time error '1004':
Application-defined or object-defined error

for this line:

iRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row


Here is what my code looks like:

Dim DestWB As Workbook
Dim DBFile As String
Dim MyPassword As String
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Sheet1")

MyPassword = "new"

DBFile = "H:\myfiles\Demo.xlsm"
Set DestWB = Workbooks.Open(DBFile, Password:="new")

'find first empty row in database
iRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row

€˜Doing My Stuff here€¦€¦

DestWB.Close True





"john" wrote:

You will need to open workbook on shared drive - something like following
should work. add code to your submit button (or whatever it is called)

Dim DestWB As Workbook
Dim DBFile As String
Dim MyPassword As String


MyPassword = "ABCD1234" '<< change as required

DBFile = "H:\WhichDirectory\WhichFile.xls" '<< change as required


Set DestWB = Workbooks.Open(DBFile, Password:="mypassword")

'do your stuff from userform here

DestWB.Close True '<< Close & save changes
--
jb


"sam" wrote:

Hi All, Can I save user inputs received from a userfrom in a seperate
workbook on shared drive?
For eg: My Userform workbook is in C drive(local) and I want to save the
inputs from the userform to a shared drive H drive(shared)

Thanks in Advance