Solved

run excel macro in shared workbook

Posted on 2011-09-29
8
434 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

707 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

16 Experts available now in Live!

Get 1:1 Help Now