Solved

run excel macro in shared workbook

Posted on 2011-09-29
8
446 Views
Last Modified: 2012-05-12
Hi Gents,

I am trying to run a macro in a shared workbook but the macro fails. If the workbook is "un -shared" then there are no issues at all.
The macro fails I think because I used the ActiveSheet. syntax and probably excel cannot determine which one is the active sheet as multiple instances are open at any given time.
I get run time error '1004' saying the" this command is not allowed on a shared workbook" etc.

Any idea how to get around this?

I am just trying to import some data in the workbook sheet with that macro and this operation has to be done while excel is in shared mode.

Any help would be greatly appreciated
Sub AA_Importandupdatedata()
'Sub Import_Data_friday()
'
' Import_Data_friday Macro
' Macro recorded 25/09/2011 by Admin
'
Columns("BK:BM").Select
    Selection.ClearContents
'
    With ActiveSheet.QueryTables.Add(Connection:= _
        "TEXT;C:\Carina_DWOR\ExportData\Friday.txt", Destination:=Range("BK1"))
        .Name = "Monday"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = xlWindows
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = True
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = True
        .TextFileSpaceDelimiter = False
        .TextFileColumnDataTypes = Array(1, 1, 1)
        .Refresh BackgroundQuery:=False
    End With
    
Range("BK1").Select
Dim rng
Dim sCell
Dim Startcell
Do
sCell = ActiveCell.Value
Startcell = ActiveCell.Address

 ActiveCell.Offset(0, 1).Select
 Selection.Copy
 Range(sCell).Select
  
 Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
 False, Transpose:=False
 Range(Startcell).Select
 ActiveCell.Offset(1, 0).Select
 Loop Until IsEmpty(ActiveCell.Offset(0, 1))
 Range("C5").Select
End Sub

Open in new window

0
Comment
Question by:Latzi_Marian
  • 4
  • 3
8 Comments
 
LVL 50

Expert Comment

by:teylyn
ID: 36818846
Hello,

Shared workbooks should be avoided. They cause all kinds of trouble and will eventually become corrupt. VBA, worksheet protection and shared workbooks don't play well together.

The unanimous advice of advanced Excel users world-wide is not to use shared workbooks. Excel was not designed for simultaneous multi-user access. If you need such functionality, you should migrate to a database like Access or SQL.

Sorry, that's probably not what you want to hear, but shared workbooks are impossible to troubleshoot, since they can become corrupt at any time and will not necessarily show consistent behaviour.

cheers, teylyn
0
 

Author Comment

by:Latzi_Marian
ID: 36818897
You are right .This is not what I wanted to hear at all. I know that excel hasn't been designed for a multiuser environment and it's very limited if used in such way. Unfortunately I will have to put up with it as the customer is simply not prepared to upgrade to a web based environment.

I actually process all the information which I want to display on that excel sheet in a SQL database using SP's and DTS's and output a flat file which should be "grabbed" by the excel macro and displayed.
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 36890159
In addition to what teylyn said, your specific issue here is trying to add a querytable. You cannot do that (in code or manually) in a shared workbook.
0
 

Author Comment

by:Latzi_Marian
ID: 36890514
Well you can but it's a very long way around . I did actually told the people involved in this that doing it in Excel is just looking for trouble and wasting time. I will try to do it in Access. That should be ok I think. What's your thoughts?

Obviously doing it in a web based environment would be the best but I have to do it in such a way that users can interact with the code behind easily,modify code,add pages ,etc . Access is what they are prepared to upgrade to.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 85

Expert Comment

by:Rory Archibald
ID: 36890518
Access should be fine, assuming you don't have hundreds of users accessing the data simultaneously.
0
 

Author Comment

by:Latzi_Marian
ID: 36890597
No no. The maximum number of users at any given time would not exceed 8. I think it's going to be ok.
0
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 500 total points
ID: 36890601
OK, Access should cope with that no problem.
0
 

Author Closing Comment

by:Latzi_Marian
ID: 37693897
decided to go with access
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

947 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now